How to ignore new changes to a tracked file with git? [duplicate]

心已入冬 提交于 2019-12-09 12:08:00

问题


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?


回答1:


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.




回答2:


Files are already tracked and now you want to ignore those files.

git rm --cached filename 
echo "filename" >> .gitignore
git add .gitignore
git commit -m 'Removes filename file and adds it to gitignore.'


来源:https://stackoverflow.com/questions/23673174/how-to-ignore-new-changes-to-a-tracked-file-with-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!