I use git a lot, and often find myself needing to make changes to a file that I absolutely don’t want to commit to the repo. For example, a default configuration file may be in the repo, but I want to change which database it is pointing to during development. Or maybe I’ll gut a CPU intensive method during preliminary testing, but I obviously don’t want the gutting method committed back to the repo.
Sure, I could stash these changes before and after every commit, but that can be a real hassle. What I like to do instead is use the assume unchanged feature.
To tell git to assume a file is unchanged, use this command:
git update-index --assume-unchanged
To undo this, use this command:
git update-index --no-assume-unchanged
A file that has been marked as assume unchanged won’t show up when you run git status. It won’t be added to a commit when you run git add -a. Pretty awesome.
If you need to figure out which files have been marked as assume unchanged, you can use this command:
git ls-files -v | grep "^[[:lower:]]"
The ls-files list with the -v option will show every file and its status, with lowercase letters for the status of assume unchanged files. The grep command will only show files that have that lowercase letter.