Unstage an added file in Git
If you added a file by mistake, you can unstage it (but keep local changes) by saying
git reset HEAD path/to/file
This is also what git status
will tell you.
NB: It works for conflicts, too, if git checkout -- <file>
does not (although git tells you it would).
Related cards:
Git: How to get a useful diff when renaming files
tldr; Use git diff -M
or git diff --find-renames
when you've moved a few files around.
Usage
$ git diff --help
Options:
-M[<n>], --find-renames[=<n>]
Detect renames. If n is specified, it is a threshold on the similarity ...
Git: What to do when "git log" does not show commits that touch a file
Let's say you have commits that change a file (and looking at the commit details show you the changes, etc). Now, when you do a git log
you see them, but when you say git log that.file
these commits don't show up? This is for you.
The reason ...
How to ignore new files or changed files in git
How to ignore new files
Globally
Add the path(s) to your file(s) which you would like to ignore to your .gitignore
file (and commit them). These file entries will also apply to others checking out the repo.
Loc...
See with tig which git commits touch a file or files or folders
tig path_to_file_or_files_or_path_with_wildcard
How to: "git log" with renamed files
While renaming a file sometimes feels like "dropping its history", that is not true: Just use git log --follow on renamed files to access their full history.
Given a file "bar" that was previously named "foo":
touch foo
git add foo
git c...
Git: How to automatically stage deleted files for commit
When you do a git add .
and have deleted files, git won’t stage them to be commited (as deleted). Use
git add -u
From the git documentation: -u
, --update <filepattern>
Only match against already tracked files in the ...
Git: Retrieve a file from a different branch or commit
To access files from another branch or past commit without doing a complete checkout, you can either use
git show branch:file
git show commit:file
to display, or check out the file into your working directory with
git checkout bra...
Where to keep project files that should not go to Git
Sometimes you have a file that is related to a project, while not actually being part of it. You'd like to keep them around, but others won't need them – e.g. some notes, a log, or a database dump.
Sure, you have a project directory – but all ...
Git: How to remove ignored files from your repository's directory
When you have files in your .gitignore
they won't be considered for changes, but still you might want to get rid of them, e.g. because they clutter your file system.
While a regular git clean
will ignore them as well, passing the -x
switch ...
Prohibit Git from merging .po-files
Merging .po-files with Git is painful.
There have been attempts of making Git more clever when trying to merge .po-files. I believe however that this is not enough as it ...