git 不会停止跟踪特定的自动生成的文件,尽管我在 .gitignore 和 `.git/info/exclude` 中排除了它

git doesn't stop tracking specific autogenerated file despite I excluded it in .gitignore and `.git/info/exclude`

Git 不会停止跟踪项目中特定的自动生成文件。 我有一个在项目 运行: platform/views/index.html 时自动生成的特定文件。我已将它添加到 .gitignore.git/info/exclude、运行 上 git rm --cached platform/views/index.html 但每次重新创建它时 git 一直问我我想做什么它。

如何使 git 永远停止跟踪此文件? 谢谢。

我的 .gitignore 文件:

dump.rdb
*.DS_Store
.vscode
.sfdx
npm-debug.log
**/.idea
**/node_modules
.vs
**/.history
newrelic_agent.log
platform/api/modules/interactions/entity-mock.js
platform/views/

如果要忽略目录中的所有文件,请使用:

platform/views/**

在 gitignore 中。如果您只想忽略一个文件,请使用:

platform/views/index.html

模式 platform/views 与文件不匹配,因此您当前的 .gitignore 不会忽略该文件。

我建议检查几个方面:

一个。 运行git check-ignore -v platform/views/index.html

如果文件被忽略:您将看到一条消息,提及 gitignore 文件和该 gitignore 文件中忽略此特定路径的模式;
如果文件未被忽略:您将看到一个空输出。

b。如果文件没有被忽略,再次运行 git rm --cached platform/views/index.html,然后确认文件忽略。

如果相关,您可以提交结果。

c。手动触发您的生成作业,并查看是否再次跟踪该文件。

这意味着您的工作 运行 相当于 git add -f platform/views/index.html 某处。

不会忽略已经提交的文件。

  1. 提交你的 .gitignore
  2. 删除有问题的文件
  3. 再做一次提交
  4. 让文件再次自动生成

然后在执行上述步骤后验证它不是新提交的一部分。