我在 .gitignore 中提到了一个文件,但我通过 git add -f
添加了它,因为我想添加
它只出现一次,然后像往常一样忽略它。
但是,现在默认情况下会对其进行跟踪。如何撤消此操作?
最佳答案
不完全确定你在寻找什么,但你可以删除要在以后的提交中忽略的文件
git rm --cached filename
Note that git will not ignore a file that was already tracked before a rule was added to this file to ignore it. In such a case the file must be un-tracked, usually with git rm --cached filename
信息:https://help.github.com/articles/ignoring-files
或者你可以告诉 git 它忽略文件的更改
git update-index --assume-unchanged filename
并用
撤消它git update-index --no-assume-unchanged filename
列出所有假设未更改的文件运行
git ls-files -v|grep '^h'
信息:How do I .gitignore and delete an already committed file without affecting other working copies?
但是请记住,assume-unchanged(在我看来)违背了 git 的理念,这个命令只会忽略它在你的机器上所做的更改。其他人仍然可以覆盖它。
在大多数情况下,您将其用于配置文件。要避免使用此选项,您可以做的是将其保留在 .gitignore 中并向自述文件添加设置说明或创建一个创建这些文件的小设置脚本。
关于gitignore 在强制添加一次后继续跟踪文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12191254/