Categories
Tech

Recovering an (un)intentionally Deleted Stash in Git

If you by accident delete your stash, that you in fact needed. Not to worry. it’s possible to recover it!
Here’s a simple step-by-step on what you can do to recover one.

Step 1

Get to a terminal with working git on it.
Open the root folder of the repo and run

git fsck
danglingcommits 

 

 

The result is ‘dangling commits’ with their hash ids. More about dangling commits here.

Step 2

Since you cannot really see which dangling commit is the lost stash that you are looking for, try some of them out.

git show 4a84d6aba6da4980c75d0de8bb9ba5151cb6d38a

You will see the changes in vi. (usually)

choosecommit

Once you go through this exercise a few times maybe and find the dangling commit you were looking for, you can do:

 git stash apply <theHashYouFound>

to apply the those changes to your “WIP” of the current branch.

 

Happy coding

A

Leave a Reply

Your email address will not be published. Required fields are marked *

10 + = 17