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?
Asked
Active
Viewed 4,464 times
2 Answers
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?
-
How do you create a patchfile out of the format-patch command ? – meson10 Oct 06 '13 at 03:17
-
1This 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 . but adl does.git rebase