Aborting a stash pop in Git

后端 未结 14 2254
鱼传尺愫
鱼传尺愫 2020-12-22 17:47

I popped a stash and there was a merge conflict. Unlike the question that is listed as a duplicate, I already had some uncommitted changes in the directory which I wanted to

14条回答
  •  感动是毒
    2020-12-22 17:51

    OK, I think I have managed to find a work-flow that will get you back to where you need to be (as if you had not done the pop).

    TAKE A BACKUP BEFOREHAND!! I don't know whether this will work for you, so copy your whole repo just in case it doesn't work.

    1) Fix the merge problems and fix all the conflict by selecting all the changes that come from the patch (in tortoisemerge, this shows up as one.REMOETE (theirs)).

    git mergetool
    

    2) Commit these changes (they will already be added via the mergetool command). Give it a commit message of "merge" or something you remember.

    git commit -m "merge"
    

    3) Now you will still have your local unstaged changes that you started originally, with a new commit from the patch (we can get rid of this later). Now commit your unstaged changes

    git add .
    git add -u .
    git commit -m "local changes"
    

    4) Reverse the patch. This can be done with the following command:

    git stash show -p | git apply -R
    

    5) Commit these changes:

    git commit -a -m "reversed patch"
    

    6) Get rid of the patch/unpatch commits

    git rebase -i HEAD^^^
    

    from this, remove the two lines with 'merge' and 'reversed patch' in it.

    7) Get your unstanged changes back and undo the 'local changes' commit

    git reset HEAD^
    

    I've run through it with a simple example and it gets you back to where you want to be - directly before the stash was popped, with your local changes and with the stash still being available to pop.

提交回复
热议问题