Undo a Git merge that hasn't been pushed yet

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

    With modern Git, you can:

    git merge --abort
    

    Older syntax:

    git reset --merge
    

    Old-school:

    git reset --hard
    

    But actually, it is worth noticing that git merge --abort is only equivalent to git reset --merge given that MERGE_HEAD is present. This can be read in the Git help for merge command.

    git merge --abort is equivalent to git reset --merge when MERGE_HEAD is present.
    

    After a failed merge, when there is no MERGE_HEAD, the failed merge can be undone with git reset --merge, but not necessarily with git merge --abort, so they are not only old and new syntax for the same thing.

    Personally I find git reset --merge much more powerful and useful in everyday work, so that's the one I always use.

提交回复
热议问题