How to restore linear git history after nonlinear merge?

前端 未结 3 1377
孤城傲影
孤城傲影 2021-02-05 16:23

Few commits ago I accidentally did a nonlinear merge in my master branch. I have a habit of always trying to keep a linear history, so now I would like to restore the linearity.

3条回答
  •  囚心锁ツ
    2021-02-05 16:57

    I think it's not that hard, just keep in mind it requires rewriting history of master:

    git checkout b9c56c9
    git rebase 3c72a2a # rebase on top of the other branch
    git cherry-pick 5506f33..master # reapply changes from merge revision (dropping it) up until the tip of master
    # if you like the results
    git branch -f master
    git checkout master
    

    And now you could force-push the branch if you already have the old master in another remote

提交回复
热议问题