Undo a Git merge that hasn't been pushed yet

前端 未结 30 2212
情歌与酒
情歌与酒 2020-11-21 22:27

Within my master branch, I did a git merge some-other-branch locally, but never pushed the changes to origin master. I didn\'t mean to merge, so I\'d like to un

30条回答
  •  醉酒成梦
    2020-11-21 23:16

    Lately, I've been using git reflog to help with this. This mostly only works if the merge JUST happened, and it was on your machine.

    git reflog might return something like:

    fbb0c0f HEAD@{0}: commit (merge): Merge branch 'master' into my-branch
    43b6032 HEAD@{1}: checkout: moving from master to my-branch
    e3753a7 HEAD@{2}: rebase finished: returning to refs/heads/master
    e3753a7 HEAD@{3}: pull --rebase: checkout e3753a71d92b032034dcb299d2df2edc09b5830e
    b41ea52 HEAD@{4}: reset: moving to HEAD^
    8400a0f HEAD@{5}: rebase: aborting
    

    The first line indicates that a merge occurred. The 2nd line is the time before my merge. I simply git reset --hard 43b6032 to force this branch to track from before the merge, and carry-on.

提交回复
热议问题