
Any remaining modified files are then unrelated to the stash, and were modified before the stash pop As such, we shouldn't need to worry about unwinding merge conflicts beyond getting back to HEAD. Which points out, the stash pop will fail if any currently unstaged modified files conflict. The second deletes any untracked files introduced by the stash.įrom man git stash : The working directory must match the index. The first reverses any merges from the stash, successful or not. git diff -name-only -cached | xargs git checkout -ours HEAD If there were no staged changes before the git stash pop, as in the question, then the following two commands should work. 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. This can be done with the following command: git stash show -p | git apply -Rĥ) Commit these changes: git commit -a -m "reversed patch"Ħ) Get rid of the patch/unpatch commits git rebase -i HEAD^^^įrom this, remove the two lines with 'merge' and 'reversed patch' in it.ħ) Get your unstanged changes back and undo the 'local changes' commit git reset HEAD^ Now commit your unstaged changes git add.
#Abort git stash pop Patch
git commit -m "merge"ģ) 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). Give it a commit message of "merge" or something you remember. git mergetoolĢ) Commit these changes (they will already be added via the mergetool command). 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.ġ) 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)). 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). Do you have any repro steps we can follow to help you out? I don't see git trying to merge my changes, it just fails. Please, commit your changes or stash them before you can merge. I am trying to repro your problem but all I get when usin git stash pop is: error: Your local changes to the following files would be overwritten by merge: That should leave your repo in the state it was before (hopefully, I still haven't been able to repro your problem) Then: git stash drop to drop the conflicting stash Git stash show and save that output somewhere if you care about it. Try hardcopying all your repo into a new dir (so you have a copy of it) and run: However, this can fail, when you have conflicts (which are stored in the index, where you therefore can no longer apply the changes as they were originally). If the -index option is used, then tries to reinstate not only the working tree's changes, but also the index's ones.


You need to resolve the conflicts by hand and call git stash drop manually afterwards. $ git merge-recursive - $(git write-tree) foo.cĮdit: From the git help stash documentation in the pop section:Īpplying the state can fail with conflicts in this case, it is not removed from the stash list. No changes added to commit (use "git add" and/or "git commit -a") " to discard changes in working directory) Nothing to commit (working directory clean) Here's an example showing how the working copy (via git status) ends up clean again: $ git status Given that your original git stash apply failed I assume the reverse might also fail since some of the things it wants to undo did not get done. You can use git reset to unstage your changes if you like. git merge-recursive - $(git write-tree) you will be left with just the non-stash changes.Then invert the merge-recursive that was done by git stash apply:

The reverse merge requires that all current changes be pushed into the index: It's more complex than git apply -reverse because you need reverse merging action in case there was any merging done by the git stash apply. Ok, I think I have worked out "git stash unapply".
