Undoing a git rebase

前端 未结 18 1724
孤城傲影
孤城傲影 2020-11-22 02:41

Does anybody know how to easily undo a git rebase?

The only way that comes to mind is to go at it manually:

  • git checkout the commit parent to both of t
18条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-22 02:52

    If you are on a branch you can use:

    git reset --hard @{1}
    

    There is not only a reference log for HEAD (obtained by git reflog), there are also reflogs for each branch (obtained by git reflog ). So, if you are on master then git reflog master will list all changes to that branch. You can refer to that changes by master@{1}, master@{2}, etc.

    git rebase will usually change HEAD multiple times but the current branch will be updated only once.

    @{1} is simply a shortcut for the current branch, so it's equal to master@{1} if you are on master.

    git reset --hard ORIG_HEAD will not work if you used git reset during an interactive rebase.

提交回复
热议问题