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?

SQB
  • 3,926
  • 2
  • 28
  • 49
0xc0de
  • 8,028
  • 5
  • 49
  • 75

2 Answers2

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?

Community
  • 1
  • 1
adl
  • 15,627
  • 6
  • 51
  • 65
  • How do you create a patchfile out of the format-patch command ? – meson10 Oct 06 '13 at 03: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 '13 at 08: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 08 '16 at 08: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.

Community
  • 1
  • 1
dpercy
  • 459
  • 6
  • 13