Git如何回滚rebase [英] Git how to rollback a rebase

查看:694
本文介绍了Git如何回滚rebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Git中,如果你不满意它,你将如何回滚rebase?



Git没有用于rebase的空转。如果我做了rebase并且还没有推它,我该如何回滚到之前,好像它从未发生过一样? 解决方案

您可以使用推荐日志在重新绑定开始并重置之前查找第一个操作 - 很难回到它。例如

  $ git reflog 

b710729 HEAD @ {0}:rebase:一些提交
5ad7c1c HEAD @ {1}:rebase:另一个提交
deafcbf HEAD @ {2}:结帐:从主人转移到我的分支
...

$ git reset HEAD @ {2} --hard

现在你应该回​​到rebase开始之前。 p>

要找到合适的地方重置,您只需选择最接近顶部的条目,以rebase开头。



另一种方法



如果你在分支上完成了这个变形只是唯一的事情即你没有任何提交/改变 - 然后你可以用 git branch -D 删除本地分支,然后再次检查它:

  $ git checkout my-branch 
$ git rebase master
//不满意结果
$ git checkout master
$ git branch -D my-branch
$ git checkout my-branch



<或者为了达到同样的效果,你可以重新设置 - 对原始分支进行重新设置:

  $ git reset --hard origin / my-branch 

如果您在执行其他未提交的提交时执行了此操作,那么您将丢失他们。在这种情况下,只需使用上面的reflog方法即可跳回到提交进行的reflog条目。


In Git, how do you rollback a rebase if you're not happy with it?

Git doesn't have dry-run for rebase. If I did a rebase and have not pushed it yet, how do I rollback to before, as if it never happened?

解决方案

You can use the reflog to find the first action before the rebase started and then reset --hard back to it. e.g.

$ git reflog

b710729 HEAD@{0}: rebase: some commit
5ad7c1c HEAD@{1}: rebase: another commit
deafcbf HEAD@{2}: checkout: moving from master to my-branch
...

$ git reset HEAD@{2} --hard

Now you should be back to before the rebase started.

To find the right place to reset to, you just pick the entry closest to top that doesn't start with "rebase".

Alternative approach

If the rebase is the only thing you have done on the branch, i.e. you have no unpushed commits/changes - then you could just delete the local branch with git branch -D and then check it out again:

$ git checkout my-branch
$ git rebase master
// not happy with result
$ git checkout master
$ git branch -D my-branch
$ git checkout my-branch

Or for the same effect, you could reset --hard to the origin branch:

$ git reset --hard origin/my-branch

If you did do this while you had other unpushed commits, then you will have lost them. In that case just use the reflog approach above to jump back to the reflog entry where you made the commit(s).

这篇关于Git如何回滚rebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆