Git“记住”了旧的未忽略文件
我在 Git 中发现了一个奇怪的问题。我的 Git 结构下有一个名为 cache 的文件夹,过去(错误地)该文件夹没有 gitignored。问题是,在一些提交之前,我将此文件夹添加到了.gitignore文件中,现在由于一些缓存更改,我注意到该文件夹中的某些文件不会被忽略。为什么?如何彻底忽略它们?
.gitignore 行很简单:
cache/*
I've found a weird problem in Git. I have a folder called cache under my Git structure that in the past (by mistake) wasn't gitignored. The problem is that some commits ago I added this folder to the .gitignore file and now due to some cache changes I have noted that some files in this folder are not ignored. Why? How to ignore them definitivelly?
.gitignore line is as simple as:
cache/*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
向
.gitignore
添加某些内容不会取消跟踪该文件。如果您想取消跟踪文件而不删除它,请使用 git rm --cached file 。这将从索引中删除文件,而不将其从工作树中删除(尽管您仍然需要提交此操作)。值得注意的是,如果您不知道的话,.gitignore 仅适用于未跟踪的文件。
Adding something to the
.gitignore
does not un-track the file. If you want to un-track the file without deleting it, usegit rm --cached file
. This will remove the file from the index without removing it from the working tree (although you still need to commit this).It's worth noting that, if you aren't aware, .gitignore only applies to untracked files.