如何将文件添加到 .gitignore 配置

How to add a file to the .gitignore configuration

我有一个工作项目,但是有一个文件我不小心推送到了远程分支,我需要在 .gitignore.

中忽略它

这是结构:

/project
  /app..
  | ...
  | ...
  /public
    | myFile.json

我在我的 .gitignore 文件中添加了这个条目:

...
/public/myFile.json
...

但它继续将其识别为传出文件。我在这里错过了什么?

您还需要从 git 中删除该文件,因为旧文件仍在跟踪中:

git rm --cached public/myFile.json

使用 --cached 文件将保留在您的本地副本中。