Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo git stash pop on dirty working tree

Tags:

git

git-stash

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?

like image 202
0xc0de Avatar asked Apr 03 '12 05:04

0xc0de


People also ask

Can you revert git stash pop?

After that just fire git stash pop again and you get the same stash, that conflicted before. Keep in mind: The stash is safe, however, uncommitted changes in the working directory are of course not. They can get messed up. What I understand is that you can simply cleanup and pop again, but you can't undo it.

How do I undo the last stash apply?

Sometimes we may need to undo a git stash apply, maybe we didn't mean to apply it at all or we just applied it to the wrong branch. Update: I've made an easy extension to git that makes this command more easy to remember, i call it gitUndo. With that extension all you need run is: git undo stash-apply.

Does git stash pop remove Stash?

When a developer uses the git stash apply command, the most recently saved stash overwrites files in the current working tree but leaves the stash history alone. In contrast, the pop command restores files but then deletes the applied stash.


2 Answers

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?

like image 161
adl Avatar answered Oct 03 '22 09:10

adl


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.

like image 35
dpercy Avatar answered Oct 03 '22 09:10

dpercy