Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个文件 (config.php),它已经提交到 Git 存储库,但我想在本地忽略,即我希望该文件保留在存储库中,但强制 Git 忽略对它的任何更改。
我将文件放入 .gitignore 中,但它仍被标记为已更改,并且每次我提交某些内容时,Git 仍在尝试对其进行更改。任何想法,我错过了什么或做错了什么?
如果文件仍然显示在状态中,即使它在 .gitignore 中,请确保它尚未被跟踪。
git rm --cached config.php
如果你只是想在本地忽略它,你也可以让它被 git status 忽略:
git update-index --assume-unchanged config.php
如评论所述,请注意,使用--assume-unchanged可能会导致不必要的数据丢失,因为git stash会将“忽略”文件重置为上游状态,撤消本地更改,而不会发出警告或保存。
--assume-unchanged
git stash
忽略签入的文件:
git update-index --assume-unchanged file
还原
git update-index --no-assume-unchanged file
全部还原
git update-index --really-refresh
如果文件已经在存储库中,因此在索引/暂存区域中,则更新.gitignore不会改变这种情况。它将继续被承诺。
.gitignore
要从索引/暂存区域中删除文件,请使用git rm <file>.
git rm <file>