如何使用git忽略对跟踪文件的新更改? [英] How to ignore new changes to a tracked file with git?

查看:151
本文介绍了如何使用git忽略对跟踪文件的新更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行git status时:

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/*

所以我将这些文件添加到了.gitignore

So I added these files to .gitignore

如何从Changes not staged for commit下的当前工作目录中删除文件?

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

推荐答案

如果我很好理解,您希望filename位于git存储库中.但是,您不希望收到有关filename的新更改的通知.您可以使用以下命令执行此操作:

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>

其他信息::编辑.gitignore只会忽略文件,因此不会将其添加到git存储库中.但是,已经被跟踪的文件将不会被忽略.

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.

这篇关于如何使用git忽略对跟踪文件的新更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆