There are times when you need to temporarily modify a file that git’s tracking, but you’ll never want to push it back to everyone else.
Of course it’s fine to modify the file and just not include it in a commit, but there is a neat solution to avoid it continually showing in git status commands.
It tended to annoy me if I did a pull and also we had some scripts that insisted on clean git repositories before they’d run. There’s always git stash of course, but this feels like an elegant way to deal with the problem.
FWIW I wasn’t so keen on the solution that I found on github here https://help.github.com/articles/ignoring-files which suggests using
git rm --cached <file>
I’d prefer to tell git to temporarily ignore the file.
With this method, it won’t show as changed in git status and it won’t get staged or committed, even in wildcard commands like git commit .
git update-index —assume-unchanged <file>
git update-index —no-assume-unchanged <file>
I sourced this from kernel.org on the link below, but note that there may be some manual work to do, described in the final paragraph:
When these flags are specified, the object names recorded for the paths are not updated. Instead, these options set and unset the “assume unchanged” bit for the paths. When the “assume unchanged” bit is on, git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell git when you change the working tree file. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).
This option can be also used as a coarse file-level mechanism to ignore uncommitted changes in tracked files (akin to what .gitignore does for untracked files). Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.