Undoing a git rebase

前端 未结 18 1579
孤城傲影
孤城傲影 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:59

    If you successfully rebased against remote branch and can not git rebase --abort you still can do some tricks to save your work and don't have forced pushes. Suppose your current branch that was rebased by mistake is called your-branch and is tracking origin/your-branch

    • git branch -m your-branch-rebased # rename current branch
    • git checkout origin/your-branch # checkout to latest state that is known to origin
    • git checkout -b your-branch
    • check git log your-branch-rebased, compare to git log your-branch and define commits that are missing from your-branch
    • git cherry-pick COMMIT_HASH for every commit in your-branch-rebased
    • push your changes. Please aware that two local branches are associated with remote/your-branch and you should push only your-branch

提交回复
热议问题