Cancel git merge but keep local changes

后端 未结 4 1037
灰色年华
灰色年华 2021-02-20 05:40

I started a git merge, but made local changes that I want to keep. I no longer want to merge, and instead continue to work on the local changes. How do I do this?

4条回答
  •  一向
    一向 (楼主)
    2021-02-20 05:42

    It happened today to me, I need to do a merge in a new branch created from develop with certain changes from another branch...

    I tried the solution from Michael Sorens but it need an additional step... git add . if you have some conflict

    git checkout -b mynewbranchfromdevelop
    git merge AnotherBranchToMergeIntoMynewbranchfromdevelop
    

    it have conflicts, I tried to make a git stash but "needs merge" messages appears, simply what I have to do is to use

    git add .
    

    to take those conflicts as resolved and staged (but still need git commit to conclude merge), then

    git stash
    

    will save those changes in a stash, and if you check with "git status" there is nothing to commit and working tree clean

    git stash apply
    

    and you will have those changes in local directory of current branch without commit

提交回复
热议问题