GIT: ignoring changes in tracked files

29/01/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
  • http://paydro.net Arjen

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

  • http://www.snappinnovations.com Sean

    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!

  • http://www.pagebakers.nl Eelco Wiersma

    Glad I could help :)

  • Pingback: Some git goodness « everyday

  • http://todosv.com Vlad88SV

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

  • http://www.pagebakers.nl Eelco Wiersma

    @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 :)

  • http://andr.esmejia.com Andrés Mejía

    Great solution! Thanks. Now I need to bookmark this page.

  • http://www.buyeyeglasses.com tamik

    thanks a lot really helped me, fast and easy…

  • http://www.sanguisdevelopment.com JOsh Beauregard

    thanx for the quick tip I learn something new every day.

  • Brett Ryan

    If you want to find all files that have been added to this list, use the following:

    git ls-files -v|grep ‘^h’

    • ramblingsoncode

      Mr. Ryan, your comment is as useful as the original post. Thank you very much.

  • Prasad

    Thanks a lot, it was very useful

  • Leong Hean Hong

    Good! This what I am looking for. Thank you.

  • Gray

    Thanks! I was trying to remember how to do this.

  • http://prabowomurti.com sangprabo

    Thank you very much!

  • Pingback: Useful post on ignoring changes in a Git repository « Thoughts by Techxplorer

  • http://medical-assistants.org/wisconsinmedicalassistantschools6.html medical assistant schools

    You have written a great post here, do you mind if I link back to you?

  • Jim

    Awesome – thanks for writing this up. Just tried it out and works perfectly.

  • hyunjungsoh

    :D Thanks so much! Please don’t delete this site! It has tons of great info! :D

  • Pingback: Bits And Pix » Git: Cheat Sheet

  • despairblue

    The definite end of the “You shouldn’t have added that file! It’s generated!”-Discussion

    Thanks so much.

  • Pingback: Note to Self » Blog Archive » Git ignore changes to tracked files

  • http://www.tinytowtimmy.com Chet Mister

    I truly wanted to type a word in order to appreciate you for all of the magnificent steps you are writing on this website. My particularly long internet search has at the end of the day been compensated with good quality facts to exchange with my great friends. I would assert that we readers are undeniably endowed to exist in a magnificent community with many outstanding individuals with valuable secrets. I feel very much blessed to have encountered your entire web pages and look forward to really more awesome minutes reading here. Thanks once more for everything.

  • basicsensei

    this is epic myfriend! thanks a bunch;)
    is there a way to save the setting in the repo somehow ?
    so that if I assume unchanged like 10 files
    and someone clones the repo, it would already have those 10 files as assumed unchanged

    • Mino

      No, this affects only your working tree. Basically you do this, if you don’t want to commit the file and at the same time .gitignore is not feasible. If you would want to bring this info to repository, you have to commit and push the information somehow, but since the command causes your changes to be ignored, you won’t see them in your commits : )

      In other words, if you have no changes in your working tree, you only have one file marked –assume-unchanged, then your next commit command will not produce anything, so there is nothing to push so the other developers don’t have anything to pull etc… : )

  • http://www.flatparaalugar.com Cariza

    i don’t know how you can write so well, your articles are excellent.http://www.flatparaalugar.com

  • http://goodfinance-blog.com ACEVEDOVeronica19

    Houses and cars are quite expensive and not everyone can buy it. But, loan are created to help people in such kind of situations.

  • Pingback: GIT: Игнорирование изменений отслеживаемых файлов | T4G – Trailer for Gang

  • Pingback: Git Roundup #1 | Gradient Studios

  • kk

    WHen I try this, I get this error:
    $ git update-index –assume-unchanged web.config
    fatal: Unable to mark file web.config

    this file is being tracked, I have to make sure I don’t accidentally commit it each time.

    • sawe

      did you manage to fix this, i get the same error

      • sawe

        apparently this is because of the casing, the command is case sensitive and gitbash’s autocomplete (pressing tab) shows web.config in lower caps, whilst the name starts with a capital letter, so change it to Web.config, and it should work

      • pagebakers

        Your should double check you’re using the correct filename, the command is case sensitive

  • Ubaid

    @— kk —

    Try running this instead (See W is capital letter):

    git update-index –assume-unchanged Web.config

    Git/Linux bash or at least this command seems case sensitive!

  • http://www.riesentasten.de Georg

    Exactly what I was looking for. Thank you!

  • Denis Kniazhev

    You saved my day. Thanks!

  • http://www.facebook.com/yashdhananjay Dhananjay Kumar Sharma

    its good!!

  • Philippe

    Thank you! Very helpful!

  • petethechop

    Thanks a million.

  • Gowiem

    This was a bit hard to find, but it did the trick. Thanks a lot.

  • Shweta kaushish

    Great Info.

  • Nilesh

    Thanks. I was not able to figure out what was going on in my branch with some changed file not showing up.Using “git update-index –no-assume-unchanged” made it work.

  • Daniel Bassa

    thanks!

  • Aren

    Thank you very goddamn much.

  • http://www.trajano.net/ Archimedes Trajano

    The problem with this one is performing a git svn rebase will wipe out your changes again. Still trying to find a way around this.

  • Pingback: git assume-unchanged implications | Technology & Programming

  • Ganesh Patil

    Thank you very much

  • akzidenzgrotesk

    Thanks! Exactly what I was looking for!
    New the command, but didn’t see the point of it… until now :)

  • HerrSerker

    Thanks for the post. One remark: If you make changes to the file later and want those to be indexed but not the other one, you have to 1) unassume changed like written above, 2) add only the changes you want with `git add –patch ` 3) assume changed again.

  • Pingback: Using constants to protect your API keys | MeetTheFalkner