【问题标题】:Update git branch after deleting a file from local system从本地系统删除文件后更新 git 分支
【发布时间】:2019-06-26 03:01:50
【问题描述】:

我删除了本地系统中的一个文件。现在我想更新 locale 分支 + 远程分支。这样该文件也会从远程分支中删除。

我做到了

git add -u

它会从本地分支中删除已删除的文件,但该文件仍保留在远程分支中。

如何从远程分支中删除文件?

【问题讨论】:

  • 您需要使用 git commit -m "Your message" 然后git push 推送您的更改以删除

标签: git-commit git-push git


【解决方案1】:

从本地存储库中删除文件后,它应该会在您推送后自动反映在远程存储库中。

您首先需要提交您的更改:

git commit -m "Removed a file"

然后使用 git push 推送您的代码

如果你想保留你的本地文件,但从网上删除它,你必须使用

git rm <file-name> --cached

如上述答案 + 您需要将其添加到您的 .gitignore 文件中,以便忽略对该文件的任何更改。

【讨论】:

    【解决方案2】:

    尝试删除缓存文件:

    git rm -r --cached .
    git add .
    git commit -m "cached problems"
    git push
    

    【讨论】:

      【解决方案3】:

      您需要推送您的更改以删除使用。确保您首先提取最新代码

      git pull
      git commit -m "Your message"
      git push
      

      【讨论】:

        【解决方案4】:

        您必须提交您的更改(删除 1 个文件):

        git commit -m "One file deletion"
        

        然后推送到远程分支:

        git push
        

        【讨论】:

          猜你喜欢
          • 2015-05-15
          • 1970-01-01
          • 2011-04-30
          • 2012-05-23
          • 2017-10-09
          • 1970-01-01
          • 2021-08-02
          • 2021-08-22
          • 2018-12-21
          相关资源
          最近更新 更多