16

This seems very foolish mistake, I just did a git stash pop on a dirty working tree. I do not know any way of keeping the desired changes and undoing the stash pop. Does one exist? Or such a mistake is unforgivable?

2 Answers 2

10

If you still have that stash's SHA1, you can generate a patch from it (git format-patch SHA1) and apply the patch in reverse (git apply -R filename.patch).

If you lost the SHA1, see How to recover a dropped stash in Git?

3
  • How do you create a patchfile out of the format-patch command ?
    – meson10
    Oct 6, 2013 at 3:17
  • 1
    This doesn't seem to work for merges; when I did git stash pop on my dirty working directory, it merged the stashed changes, so git format-patch SHA1 didn't do anything. Any ideas for a workaround?
    – Will
    Nov 23, 2013 at 8:28
  • It doesn't work for me either, when changes from popped stash are merged, creation of the patch gives me empty patch file. Does anybody know how to workaround this ?
    – Lazureus
    Jan 8, 2016 at 8:42
1

git stash pop does 2 things: git stash apply and git stash drop. If you can undo the drop, using this question and answers, then you'd just have to undo the apply. I'm not sure how to do this, but you might look into git rebase. but adl does.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.