文件夹添加它 .gitignore 仍然出现在 Git 更改中

Folder added it .gitignore still showing up in the Git changes

好的,所以我最近升级到 Angular 13,现在我有了这个文件夹名称“.angular”。

我在 .gitignore 文件中将它的条目添加为 .angular/cache 因为它不想跟踪它,但是其中的文件总是在 git 更改中显示为未跟踪文件.

几乎 Whosebug 上的每个答案都告诉 运行 以下命令。

git rm -r --cached .
git add .
git commit -m ".gitignore is now working"

所有这一切都是暂存未跟踪的文件,然后对它们进行提交。我的 .angular 文件夹仍在被跟踪。它仍然没有像 node_modules 那样变灰,这意味着 git 没有忽略它。

我应该做些不同的事情吗?

如果 .angular 中还有其他 folders/files 而您只忽略 .gitignore 文件中 .angular/cache 的文件夹 cache,则 .angular 将继续跟踪文件夹。

因此您必须忽略 .gitignore 中包含 .angular/ 的整个 .angular 文件夹。

在此之后,.angular 文件夹将像您提到的 node_module 文件夹一样变灰。

假设在你的存储库的根文件夹中有一个 .gitignore,我会尝试:

cd /path/to/repo
echo ".angular/cached/">>.gitignore
git rm -r --cached .angular/cached/
git add .
git commit -m "Remove and ignore .angular/cached