【问题标题】:Revert commits back after the head was changed and pushed在头部被更改并推送后恢复提交
【发布时间】:2015-08-07 18:41:42
【问题描述】:

几天前我提交了一些糟糕的代码,今天我改变并推动了一个老头。

换头前:

提交 4

提交 3 - 错误代码从这里开始

commit 2 - 我在这里设置头部并推送

提交 1

换头后:

提交 2 - 当前负责人

提交 1

问题是现在我想要那些“错误的提交”。

有可能找回它们吗?

【问题讨论】:

    标签: git github git-push git-commit git-reset


    【解决方案1】:

    您可以使用git reflog来解决您的问题:

    git reflog
    a8U3Ild... HEAD@{10}: commit 3
    e3Noj1q... HEAD@{11}: commit 4
    

    找到您删除的提交的SHA-1 哈希值。您想要的提交是“commit 4”的提交,它是您回滚之前分支的负责人。然后您可以像这样将当前分支重置为“commit 4”:

    git checkout master
    git reset --hard e3Noj1q
    

    【讨论】:

      【解决方案2】:

      如果您已删除的提交仍然在 reflog 中被引用,您应该能够按照此处的说明恢复它们:
      http://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery#Data-Recovery

      git reflog 手册页:http://git-scm.com/docs/git-reflog
      git fsck 手册页:http://git-scm.com/docs/git-fsck

      【讨论】:

        猜你喜欢
        • 2013-04-20
        • 2016-07-20
        • 2020-12-18
        • 2018-07-01
        • 2012-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多