Undo a Git merge that hasn't been pushed yet

前端 未结 30 2640
情歌与酒
情歌与酒 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:00

    It is strange that the simplest command was missing. Most answers work, but undoing the merge you just did, this is the easy and safe way:

    git reset --merge ORIG_HEAD
    

    The ref ORIG_HEAD will point to the original commit from before the merge.

    (The --merge option has nothing to do with the merge. It's just like git reset --hard ORIG_HEAD, but safer since it doesn't touch uncommitted changes.)

提交回复
热议问题