Undo a Git merge that hasn't been pushed yet

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

    If your merge and the corresponding commits were not pushed yet, you can always switch to another branch, delete the original one and re-create it.

    For example, I accidentally merged a develop branch into master and wanted to undo that. Using the following steps:

    git checkout develop
    git branch -D master
    git branch -t master origin/master
    

    Voila! Master is at the same stage as origin, and your mis-merged state is erased.

提交回复
热议问题