Temporarily ignoring files on GIT for Windows.

Sometimes you want to temporarily modify a file in a git repository, but don’t want to risk accidentally committing it. Maybe you are tweaking a config file, or updating the logging config temporarily while you investigate a bug.

Luckily, you can do this in git. Essentially you update git’s index to tell it the file IS unchanged (regardless of what git *might* think!).


git update-index --assume-unchanged

To undo this simply run:

git update-index --no-assume-unchanged

Of course, you will also want to see all the files you currently have ignored. You can use the following command:


# -v: use lowercase letters for files that are marked as assume unchanged
# The select-string is just finding any line that starts with a lowercase letter.
git ls-files -v | select-string -CaseSensitive "^[a-z]"

I added the following to my git config (in C:\ProgramData\Git\config). Note that you need to use FINDSTR as git commands execute in cmd, not powershell.


[alias]
ignore = !git update-index --assume-unchanged
unignore = !git update-index --no-assume-unchanged
ignored = !git ls-files -v | FINDSTR ^[abcdefghikjklmnopqrstuvwxyz]