git: how to move a branch's root two commits back

后端 未结 3 1470
闹比i
闹比i 2021-01-07 01:44

Let\'s say I have:

A - B - C - D - E - F  master
            \\ 
             \\- G - H  new feature branch

Now I realize that commits B an

3条回答
  •  执笔经年
    2021-01-07 02:46

    To fix master:

    git checkout A
    git cherry-pick master~3..master # apply the changes we actually want to keep on master
    git branch -f master # reposition master on new position
    git checkout master
    

    To drop commit D from the feature branch:

    git checkout feature-branch~3 # or git checkout C
    git cherry-pick feature-branch~2..feature-branch # apply the last 2 revisions
    git branch -f feature-branch
    git checkout feature-branch
    

提交回复
热议问题