【问题标题】:How should I hide my googleservices.json file using .gitignore?我应该如何使用 .gitignore 隐藏我的 google services.json 文件?
【发布时间】:2020-10-02 13:29:49
【问题描述】:

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

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

【问题讨论】:

    标签: git gitignore


    【解决方案1】:

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

    但是,如果您已经提交,它将永远在您的回购历史中可见。如果您想将其从历史记录中删除,则必须重新设置整个 repo 的基础,就好像添加该文件的提交从未存在一样,或者干脆从头开始。

    另见:How to permanently delete a file stored in GIT?

    【讨论】:

    • 先生,您能告诉我现在如何变基的步骤吗?
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      *.json
      

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

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

      在你的 .gitignore 中添加文件。

      进入android/app/后运行以下命令

      git rm --cached googleservices.json
      

      提交删除文件和更新的 .gitignore 到你的仓库

      【讨论】:

        猜你喜欢
        • 2017-08-29
        • 2018-03-29
        • 1970-01-01
        • 2019-06-16
        • 1970-01-01
        • 1970-01-01
        • 2017-10-12
        • 2018-09-30
        • 1970-01-01
        相关资源
        最近更新 更多