gitignore 在强制添加一次后继续跟踪文件

标签 git gitignore

我在 .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/

相关文章:

带 merge 的 Eclipse EGit Rebase

Git rebase 2 个提交由 2 个分支共享

git - 如何撤消 git update-index?

Android Volley : comes with a . gitignore

git - 如何将本地 Git 分支推送到远程的 master 分支?

git - 如何制作 7zip 格式的 git 存档?

git - 为什么 git amend 在没有什么要修改的时候不警告你?

git - .gitignore 排除包含文件的文件夹但包含子目录

git - 在 git 上可以安全忽略哪些报告服务文件类型?

android-studio - 在 flutter 中将文件添加到git忽略