Undoing a git merge

前端 未结 2 1898
南方客
南方客 2021-02-20 14:45

I\'m not that experienced with Git and now I have a big problem falling into my lap.

Here\'s how my current branch look like:

feature       /---F1-----F2         


        
2条回答
  •  天涯浪人
    2021-02-20 14:58

    So to clarify, what you want is this, right?

    feature       /---F1-----F2
                 /                 
    master -----M0-----M1-----M2
                 \            
    bugfix        \--B1-----B2
    

    Make sure that the HEADs feature and bugfix are still on F2 and B2 respectively.

    Edit: if feature and bugfix are no branches, make them branches (stash your work if it is uncommited):

    git checkout F2
    git branch feature
    git checkout B2
    git branch bugfix
    

    Edit end

    Then reset the master to M2:

    git checkout master
    git reset M2 --hard
    

    (reset will make you lose your local changes, stash them if you don't want that.)

    M3 and M4 are not destroyed right away, but will be eventually. They should not show up in git log or gitk.

    Then it's time to merge feature and make a M3' that is correct.

提交回复
热议问题