gitignore文件无法忽略存储库中的文件

3
我已经定义了以下的 .gitignore 文件:
/aclocal.m4
/config.guess
/config.sub

然而在重新配置和重建之后,git status 仍然报告如下:
# On branch master
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   aclocal.m4
#       modified:   config.guess
#       modified:   config.sub
...

I'm expecting it to say something like:

#       deleted:    aclocal.m4
...

我在这里做错了什么?

你之前追踪过那些文件吗? - Tim
已经在 Git 中的文件优先于 .gitignore 的定义。.gitignore 只会防止新文件进入 Git 领域,而不会将现有文件从中删除。这使您保持控制,您不希望由于 gitignore 文件中的错误而自动清除存储库,对吗? - Newtopian
2个回答

7

听起来这些文件已经被 Git 跟踪了。在这种情况下,您首先需要从 Git 中删除它们(例如 git rm filename)。然后它们将被忽略。


4
你正在引用位于文件系统根目录而不是你的代码库中的文件。
你需要像这样做:
```html ... ```
请注意,这里的文件路径应该相对于你的代码库。
aclocal.m4
config.guess
config.sub

如果他们之前已经将它们添加到仓库中,您还需要将它们移除(例如git rm aclocal.m4)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接