Git: Temporarily ignoring files
On some occasions you may need to ignore few files without touching 'gitignore' (e.g. local configuration). To achieve that you simply issue following command:
git update-index --assume-unchanged <file_to_ignore>
From now on the file will be excluded from the list of changes. You can safely use 'git add'. To see what's ignored use:
git ls-files -v | grep ^h
To stop ignoring file you simply execute:
git update-index --no-assume-unchanged <ignored_file>
You may find alisases more handy to use. Add them to either ~/.gitconfig (global) or .git/config (repository)
[alias]
ignore = !git update-index --assume-unchanged
unignore = !git update-index --no-assume-unchanged
ignored = !git ls-files -v | grep ^[a-z]
Written by cSquirrel
Related protips
7 Responses
I would prefer skip
aliases instead of ignore
because I use ignore
command to add file to .gitignore
.
Thx for sharing those useful tips!
I've the problem that I get "fatal: Unable to mark file ..." when I try to ignore a file. What could be the problem?
@daniel-marschner Is the file in the repo yet? The update-index action only works on files that are in your repo. If its not in the repo yet, you can add it to .gitignore.
This didn't work for me when I added it to .gitconfig but does work when added to my .bashrc with some minor changes - could be the setup at work.
But thank you for sharing this - its a great tip.
@juanfernandes: That's bizzare because these are git alias definitions. They shouldn't be processed by shell (.bashrc) but by git itself (.gitconfig).
@csquirrel Oh really. That is weird as all my git aliases are in my .bashrc file
The aliases are for Git itself, as in "git [alias]".