【问题标题】:Folder added it .gitignore still showing up in the Git changes文件夹添加了它 .gitignore 仍然显示在 Git 更改中
【发布时间】:2021-12-25 11:30:01
【问题描述】:

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

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

StackOverflow 上的几乎每个答案都要求运行以下命令。

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

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

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

【问题讨论】:

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

标签: git gitignore


【解决方案1】:

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

所以你必须忽略整个.angular 文件夹和.angular/.gitignore

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

【讨论】:

  • 我不介意 .angular 文件夹本身被跟踪,但 git 也在跟踪缓存文件夹中的每个文件,尽管我在 .gitignore 中明确提到了 .angular.cache忽略。
  • 所以你的问题不是很清楚......但问题是文件夹结构和你的.gitignore条目与你的角度项目不同。在cache文件夹中找出带有pwd的文件夹结构,并将路径复制到.gitignore中的git-root。
【解决方案2】:

假设您的存储库的根文件夹中有一个.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

【讨论】:

    猜你喜欢
    • 2012-04-02
    • 2021-02-24
    • 1970-01-01
    • 2016-07-11
    • 2013-12-28
    • 2016-02-16
    • 1970-01-01
    • 2016-04-09
    • 2020-12-31
    相关资源
    最近更新 更多