Undoing a git rebase

前端 未结 18 1611
孤城傲影
孤城傲影 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 03:12

    Let's say I rebase master to my feature branch and I get 30 new commits which break something. I've found that often it's easiest to just remove the bad commits.

    git rebase -i HEAD~31
    

    Interactive rebase for the last 31 commits (it doesn't hurt if you pick way too many).

    Simply take the commits that you want to get rid of and mark them with "d" instead of "pick". Now the commits are deleted effectively undoing the rebase (if you remove only the commits you just got when rebasing).

提交回复
热议问题