Search code examples
gitgitignoreignore

How to ignore new changes to a tracked file with git?


"Duplicate" link is NOT the same. The linked question is to remove a file completely, this question is about leaving the file in the repo but ignoring subsequent updates.


When I run git status:

$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   .gitignore
#       modified:   .project
#       modified:   reports/images/2014-03.png
#       modified:   reports/images/graph-2014-03.bmp
#       deleted:    reports/phpbmp/cache/0/02/027/0270/phpThumb_cache_portal.gep.co.za_src02707010e1e50bc80594
f31460d514c4_par80d8993b181666aca11d7be02b12fea7_dat1399293161.bmp
#       deleted:    reports/phpbmp/cache/0/02/027/0270/phpThumb_cache_portal.gep.co.za_src02707010e1e50bc80594
f31460d514c4_par80d8993b181666aca11d7be02b12fea7_dat1399293182.bmp
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       README.MD
#       reports/phpbmp/cache/9/
no changes added to commit (use "git add" and/or "git commit -a")

I realised that I don't want changes to the following files be tracked:

.project
reports/images/*.png
reports/images/*.bmp
reports/phpbmp/cache/*

So I added these files to .gitignore

How do I remove the files from the current working directory under Changes not staged for commit?


Solution

  • If I understand well you want filename to be in the git repository. However you don't want to be notified of new changes to filename. You can do this using this command:

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

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

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

    additional info: editing .gitignore will only ignore files so they will not be added to the git repository. However files that are tracked already will not be ignored.