如何忽略存储库中的文件?
我有一个文件 (config.php
),已提交到 Git 存储库,但我想在本地忽略,即我希望该文件保留在存储库中,但强制 Git 忽略任何更改到它。
我将文件放入 .gitignore
中,但它仍然被标记为已更改,并且每次我提交某些内容时,Git 仍然会尝试向它提交更改。
有什么想法,我错过了什么或做错了什么吗?
I have a file (config.php
), that is already committed to a Git repository, but I want to ignore locally, i.e. I want that file to remain in repository, but force Git to ignore any changes to it.
I put the file into .gitignore
, but it is still marked as changed and Git still is attempting to commit changes to it, every time I commit something.
Any ideas, what am I missing or doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果文件仍然显示在状态中,即使它位于 .gitignore 中,请确保它尚未被跟踪。
如果你只是想在本地忽略它,你也可以让它被 git status 忽略:
如 评论,请注意使用
--assume-unchanged
可能会导致不必要的数据丢失,因为git stash
将“忽略”的文件重置为上游状态,撤消本地更改,而不发出警告或保存。If the file is still displayed in the status, even though it is in the .gitignore, make sure it isn't already tracked.
If you just want to ignore it locally, you could also make it ignored by the git status:
As commented, do note that using
--assume-unchanged
might cause unwanted data loss asgit stash
resets the "ignored" files to the state in upstream, undoing local changes, without a warning or saving.忽略签入文件:
要恢复
全部恢复
Ignore checked in file:
To revert
Revert All
如果文件已经在存储库中,并且因此在索引/暂存区域中,则对
.gitignore
的更新不会改变这种情况。它将继续致力于。要从索引/暂存区域中删除文件,请使用 git rm。
If the file is already in the repository, and hence the Index/Staging area, then an update to
.gitignore
won't change that situation. It would keep being committed.To remove the file from the Index/Staging area use
git rm <file>
.