Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用git忽略对跟踪文件的新更改?_Git_Gitignore_Ignore - Fatal编程技术网

如何使用git忽略对跟踪文件的新更改?

如何使用git忽略对跟踪文件的新更改?,git,gitignore,ignore,Git,Gitignore,Ignore,当我运行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) # # mo

当我运行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")
因此,我将这些文件添加到
.gitignore


如何从当前工作目录中的
未为提交而暂存的更改下删除文件?

文件已被跟踪,现在您希望忽略这些文件

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

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

git update-index --assume-unchanged <filename>
git更新索引--假定未更改
如果要再次开始跟踪更改,请运行以下命令:

git update-index --no-assume-unchanged <filename>
git更新索引——无假设不变

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

这给了我:
#要提交的更改:#(使用“git reset HEAD…”取消存储)##删除:.project
,这难道不意味着当有人从repo中提取时,文件将被删除或根本不存在吗?是的;将从存储库中删除您的文件。。。我想你需要使用——假设不变……问题是,如果你的更改仍然会导致冲突,那么它们将更难检测。您也将无法隐藏或提交更改,因此您可能最终无法
git checkout
到其他分支。是的。重要的是要注意,我认为以上是不好的做法。如果您不想跟踪更改,最好从repo中删除这些文件。我对文件执行了此操作,现在当我对其进行更改并拉入
时,您对以下文件的本地更改将被合并覆盖:请在合并之前提交更改或将其隐藏。正在中止
git update-index --no-assume-unchanged <filename>