Some time ago I used Subversion as a revision control system for developed software. It’s pretty simple to use it, but eventually it became too simple and too complicated at the same time in working with branches, tags, etc. So, I decided to use git for this purposes.
I used TortoiseSVN to make commits and other stuff while use Subversion. There was a very good feature as “ignore-on-commit” change list. This feature allows hide files when you make a commit, but keeps it in index and new ‘svn checkout …’ gets those files from repository.
When I moved to work with git I had a little problem. I didn’t find such thing. Using .gitignore is not the same way to not track changes in custom files, because .gitignore hides file from git index too, but I need to keep this files in repository like as default templates for environment configs and etc.
Some times ago, I found a way to such feature in git, so here it is.
Add a file to ignore-on-commit list
To hide changes in a file you need to execute the command:
git update-index --assume-unchanged <file>
This command hides changes in the file for git status and git will think that the file doesn’t have any unstaged changes. Git will not touch the file when you switch branches (without –hard or –force option).
Delete a file from ignore-on-commit list
Next command tells git to start again track changes in the file:
git update-index --no-assume-unchanged <file>
View files in ignore-on-commit list
To see the list of hidden from git files execute the following command:
git ls-files -v | grep '^h'