Undo a git merge (hasn't been pushed yet)

后端 未结 4 673
孤城傲影
孤城傲影 2021-01-30 10:30

I just committed some changes into one of my feature branches (\"feedback_tab\") then, checked out \"master\" and merged them in there. I actually meant to merge them into my \

相关标签:
4条回答
  • 2021-01-30 11:08

    To undo a merge that was NOT pushed:

    git reset --merge ORIG_HEAD
    

    If during the merge you get a conflict, the best way to undo the merge is:

    git merge --abort
    
    0 讨论(0)
  • 2021-01-30 11:10

    This one will surely work!

    git reset --hard HEAD~1 
    git init
    

    The first one will revert the changes you recently made (the merge) the second will init the repo to latest (therefore will fast forward to latest on origin)

    I've tried

    git reset --merge
    

    but it didn't do the trick.

    0 讨论(0)
  • 2021-01-30 11:24

    Taken from git reset

    Undo a merge or pull
    
        $ git pull                         <1>
        Auto-merging nitfol
        CONFLICT (content): Merge conflict in nitfol
        Automatic merge failed; fix conflicts and then commit the result.
        $ git reset --hard                 <2>
        $ git pull . topic/branch          <3>
        Updating from 41223... to 13134...
        Fast-forward
        $ git reset --hard ORIG_HEAD       <4>
    
    0 讨论(0)
  • 2021-01-30 11:25

    git reset --hard HEAD~17 takes you back 17 commits ahead of the head of master. git rebase -i HEAD~17 probably gets rid of the extra commits as well.

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