Ignoring files in git that are in the repository

Often I find that I am working on a project that has files under version control that I need to change in my environment, but never commit. A frequent example is the database.yml file in a rails project. Let’s put aside all the reasons you really shouldn’t have a file like this under version control for now and assume this was not in your control. Having the file always show up as modified is both annoying and makes it easy to accidentally commit changes. Since the file is actually version controlled, you can’t just add it to .gitignore, but there is a solution.

$ git update-index --assume-unchanged config/database.yml

Now, git will happily pretend you have not made any changes to the file. If you need to put things back the way they were:

$ git update-index --no-assume-unchanged config/database.yml

Very handy!

Leave a Reply

Your email address will not be published. Required fields are marked *