【问题标题】:How to undo git push without changing the local code?如何在不更改本地代码的情况下撤消 git push?
【发布时间】:2016-09-20 11:07:02
【问题描述】:

我很困惑推送所有文件代码,包括 android studio 中 .gitignore 中的 lib 文件。我们如何在不更改本地代码的情况下撤消 git push 文件。恐怕,如果我重置 Head,我的新本地代码会被忽略。

我对 git 很陌生。请帮助并感谢。

【问题讨论】:

    标签: git android-studio gitignore git-push


    【解决方案1】:

    只需“备份”您当前的 HEAD,例如:

    git tag tmptag
    git reset --hard HEAD^
    git push --force
    git reset --hard tmptag
    git tag --delete tmptag
    

    顺便说一句,不要害怕。真正错误地删除提交是很困难的。通常你总是使用git reflog 看到所有最近的提交。不用像我上面提到的那样创建这样的备份标签,您可以将分支重置为旧的原始 sha1 哈希,即使在历史记录中没有现有的分支或标签有这个提交。您甚至可以使用特殊标识符 ORIG_HEAD,而无需复制/粘贴任何 sha1 哈希。

    【讨论】:

      猜你喜欢
      • 2017-11-12
      • 2021-05-17
      • 2014-11-03
      • 2011-09-21
      • 2010-11-19
      • 2012-02-29
      • 1970-01-01
      • 2016-10-03
      • 2011-12-07
      相关资源
      最近更新 更多