I love developing usable and rich web applications using the latest techniques available.

GIT: ignoring changes in tracked files

January 29, 2009

There may be times when you want to edit some variables in for example a database connection file, to run an application right from within your GIT repo. Of course you don’t wont those changes to be commited, so you add the file the .gitignore.
However adding tracked files to .gitignore won’t work because GIT will still track the changes and commit the file if you use the -a parameter.

Fortunately GIT has a very easy solution for this, just run the following command on the file or path you want to ignore the changes of:

git update-index --assume-unchanged <file>

If you wanna start tracking changes again run the following command:

git update-index --no-assume-unchanged <file>

You can find more info about this in the git manual.

Happy GITting ;)

Bookmark and Share
Filed under: Webdevelopment

8 Comments »

  1. Thanks. Last time I just deleted the file, but this is way better.

    19/02/2009 @ 6:17 pmArjen
  2. Where were you just two days ago. I was banging my head on the walls to try to find an easy solution like this. Thanks for the trip, definitely use it!

    24/03/2009 @ 9:07 amSean
  3. Glad I could help :)

    27/03/2009 @ 3:19 pmEelco Wiersma
  4. [...] searching for a solution today, I ran across this little gem of an article titled “GIT: ignoring changes in tracked files” from Pagebakers.nl, the salient code is [...]

  5. And how you can propagate that change to the remote repository?, so I can share this “ignore” with everybody? :)

    15/07/2009 @ 11:18 pmVlad88SV
  6. @Vlad88SV

    Well.. if you want to accomplish that, you need to add files / directories to .gitignore before they get tracked by git..

    let’s say you have a tmp directory in your application and you don’t want to track the files in there, create a .empty (else the tmp dir will not be commited in the repo) file in there, commit it.. then add ‘tmp/*’ in your .gitignore file and commit again. Then it will be shared with other people :)

    good luck :)

    18/07/2009 @ 12:16 amEelco Wiersma
  7. Great solution! Thanks. Now I need to bookmark this page.

    26/11/2009 @ 5:15 pmAndrés Mejía
  8. thanks a lot really helped me, fast and easy…

    15/08/2010 @ 3:12 pmtamik

Leave a comment