首先,制作 git 工作文件夹的 tarball。这样可以更轻松地尝试多次。
让我们假设发生了以下情况
- git checkout another-old-branch
- git rebase 大师
- 一些问题(你跳过了)
此时,您现在仍在另一个旧分支中,并且您的 reflog 向您显示:
6f8348f HEAD@{0}: rebase: <commit message of last commit in another-old-branch>
e547ec0 HEAD@{1}: checkout: moving from another-old-branch to e547ec0d2a558d189464fc57192066b34ec5f28f^0
65cedf8 HEAD@{2}: checkout: moving from master to another-old-branch
想象一下分支就像符号链接(或指针),我们所要做的就是让分支'another-old-branch'指向旧的提交ID。旧的提交仍然存在,并且您的变基没有触及它。有点:'嘿 git,另一个旧分支是 e547ec0d2,忘记发生的所有其他事情'
在我们的例子中是 e547ec0d2a558d189464fc57192066b34ec5f28f,所以我们现在要做的是
- git checkout another-old-branch # 如果你还没有
- git reset --hard e547ec0d2a558d189464fc57192066b34ec5f28f
现在您的分支已恢复正常。你可以重试你的变基。
请注意,您的 reflog 现在比上面的示例要复杂一些。但它应该仍然存在于某个地方......
祝你好运!