Undoing a git merge

前端 未结 2 1958
南方客
南方客 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.

    0 讨论(0)
  • 2021-02-20 15:01

    If you didn't push (publish) the merge commits yet, use git reset. E.g. on the master branch, assuming your working tree is clean, do git reset --hard .

    More info: Undo a Git merge that hasn't been pushed yet

    If you did publish your changes you might want to consider making a revert commit instead. More info here: http://progit.org/2010/03/02/undoing-merges.html

    0 讨论(0)
提交回复
热议问题