Undo a Git merge that hasn't been pushed yet

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

    It can be done multiple ways.

    1) Abort Merge

    If you are in-between a bad merge (mistakenly done with wrong branch), and wanted to avoid the merge to go back to the branch latest as below:

    git merge --abort
    

    2) Reset HEAD to remote branch

    If you are working from remote develop branch, you can reset HEAD to the last commit on remote branch as below:

    git reset --hard origin/develop
    

    3) Delete current branch, and checkout again from the remote repository

    Considering, you are working on develop branch in local repo, that syncs with remote/develop branch, you can do as below:

    git checkout master 
    ##to delete one branch, you need to be on another branch, otherwise you will fall with the branch :) 
    
    git branch -D develop
    git checkout -b develop origin/develop
    

提交回复
热议问题