Cancel git merge but keep local changes

后端 未结 4 1062
灰色年华
灰色年华 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:52

    Language is notoriously ambiguous. :-) When you say "keep local changes" you could mean either:

    1. keep all current changes in the working directory, whether you manually edited those files OR the merge that you are in the middle of brought them in; or
    2. discard any changes brought in by the merge and retain any changes that you have introduced.

    This simple solution addresses point (1):

    $ git stash save
    $ git stash pop
    

    Here's a transcript showing the affect:

    $ git status
    On branch stuff-217/apply-new-config-details
    All conflicts fixed but you are still merging.  <<<<<< notice this line!
    
    Changes to be committed:
            modified:   package.json
            modified:   src/wallabyTest.ts
            modified:   wallaby.js
    
    $ git stash save
    Saved working directory and index state WIP on stuff-217/apply-new-config-details...
    
    $ git status
    On branch stuff-217/apply-new-config-details
    nothing to commit, working tree clean
    
    $ git stash pop
    On branch stuff-217/apply-new-config-details
                                                 <<<<<< no longer in the merge!
    Changes not staged for commit:
            modified:   package.json
            modified:   src/wallabyTest.ts
            modified:   wallaby.js
    

提交回复
热议问题