我应该如何使用 .gitignore 隐藏我的 googleservices.json 文件?

How should I hide my googleservices.json file using .gitignore?

我想对 git 隐藏我的 googleservices.json,因此我想将它添加到 .gitignore 文件。 我的 googleservices.json 文件位于 android/app/googleservices.json

当我将此位置添加到 .gitignore 文件时,它仍然跟踪它,我该怎么办?

如果您已经提交过一次,则必须明确删除它。 git rm 会这样做。

但是,如果您已经提交,它将永远显示在您的回购历史记录中。如果你想从历史中删除它,你将不得不重新设置整个 repo,就好像添加文件的提交从未存在过一样,或者只是从头开始。

另请参阅:How to permanently delete a file stored in GIT?

您需要从 git 缓存中删除该文件 git rm --cache googleservices.json

只需将这一行添加到 gitignore 文件

*.json

如果您想永久忽略对文件的更改,那么更安全的方法是从 Git 的索引中删除有关该文件的信息。

这些步骤不会从您的系统中删除文件。他们只是告诉 Git 忽略将来对文件的更新。

在你的 .gitignore 中添加文件。

运行进入android/app/

后执行以下命令
git rm --cached googleservices.json

提交删除文件和更新后的 .gitignore 到您的存储库