文件夹已添加到.gitignore,但仍然显示在Git更改中。

3

好的,我最近升级到了Angular 13,现在有这个文件夹名字是".angular"。

我已经在.gitignore文件中添加了它的条目.angular/cache,因为我不想跟踪它,但是它内部的文件始终显示为未跟踪的文件。

StackOverflow上几乎所有的答案都建议运行以下命令。

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

这只是将未跟踪的文件暂存,然后将其提交。我的.angular文件夹仍在被跟踪。它仍然没有像node_modules那样变灰,这意味着Git没有忽略它。

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


应该在哪个.gitignore文件中精确匹配.angular目录的行是什么?它可能已经添加到了git中吗?尝试使用git check-ignore进行调试。 - acran
我已经在.gitignore文件中,在node_module文件夹下面添加了.angular/cache这一行。@acran - mfs
2个回答

5
如果在 .angular 文件夹中有其他文件或文件夹,并且你只想忽略 .gitignore 文件中的 .angular/cache 文件夹,则 .angular 文件夹将继续被跟踪。
因此,你必须在 .gitignore 文件中使用 .angular/ 来忽略整个 .angular 文件夹。
完成后,.angular 文件夹将像你提到的 node_module 文件夹一样变灰。

我不介意跟踪.angular文件夹本身,但是尽管我已经明确在.gitignore中提到了.angular.cache以使其被忽略,但git仍然跟踪缓存文件夹中的每个文件。 - mfs
1
所以你的问题不是很清楚...但问题肯定出在文件夹结构上,而且你的.gitignore条目与你的angular项目并不相同。在“cache”文件夹中使用“pwd”查找文件夹结构,并将路径复制到.gitignore中的git根目录。 - SwissCodeMen
1
感谢 @SwissCodeMen。我将.angular/添加到.gitignore中,它删除了我不想查看的n个未跟踪文件。 - Vishesh

1
假设您的代码库根目录下有一个名为.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

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