Ignoring local changes to a file in git repository
Let’s say you want to modify a file in your repository locally and don’t commit that. For example, you might want to use a different .rvmrc than the rest of the team, or you might want to disable a non-essential gem or a part of the system that has some problems on your OS.
Of course an ideal way would be to fix it in the repo so that it works for everyone, but sometimes that’s not possible. You could make the change and just remember not to commit it, but you can be sure you’ll forget sooner or later.
In this case, the solution is to mark the file as ignored in your local repository. There is something like a “local gitignore”, which is located at .git/info/exclude, but that won’t work if the file is already in the repository. You need to use the update-index command instead:
git update-index --assume-unchanged .rvmrc
The file will just disappear from git status and will behave as if you didn’t modify it at all. If you change your mind, this is how you remove that “unchanged” flag:
git update-index --no-assume-unchanged .rvmrc
If you forget which files you’ve marked as unchanged and you want to see a list, it seems the only way to do that is by using this command:
git ls-files -v | grep ^[a-z]
This works because files marked as unchanged show up in ls-files marked with a lowercase character. (If you know a less hacky way to print that list, let me know…).
P.S. Don’t forget about the Krakow Ruby User Group meeting tomorrow!