【发布时间】:2020-10-02 13:29:49
【问题描述】:
我想从 git 中隐藏我的 googleservices.json,因此我想将它添加到 .gitignore 文件中。 我的 googleservices.json 文件位于 android/app/googleservices.json 中
当我将此位置添加到 .gitignore 文件时,它仍然会跟踪它,我该怎么办?
【问题讨论】:
我想从 git 中隐藏我的 googleservices.json,因此我想将它添加到 .gitignore 文件中。 我的 googleservices.json 文件位于 android/app/googleservices.json 中
当我将此位置添加到 .gitignore 文件时,它仍然会跟踪它,我该怎么办?
【问题讨论】:
如果您已经提交过一次,则必须明确删除它。 git rm 会这样做。
但是,如果您已经提交,它将永远在您的回购历史中可见。如果您想将其从历史记录中删除,则必须重新设置整个 repo 的基础,就好像添加该文件的提交从未存在一样,或者干脆从头开始。
【讨论】:
您需要从 git 缓存中删除该文件
git rm --cache googleservices.json
【讨论】:
只需将这一行添加到 gitignore 文件中
*.json
如果您想永久忽略对文件的更改,那么更安全的方法是从 Git 的索引中删除有关该文件的信息。
这些步骤不会从您的系统中删除文件。他们只是告诉 Git 忽略文件的未来更新。
在你的 .gitignore 中添加文件。
进入android/app/后运行以下命令
git rm --cached googleservices.json
提交删除文件和更新的 .gitignore 到你的仓库
【讨论】: