What to do after you blow your (git) stash

How to recover git stashes after accidentally deleting them.

Posted by Orville Bennett on 25 April 2020
Read time: about 1 minutes

I just blew my stash!

So I had occasion to be doing some code cleanup late at night and I accidentally deleted some git stashes I had around. Now the code was super important, I didn't actually remember what was in those stashes. But this was git so I figured I could get it back.

My first thought was to use the reflog, but a git reflog didn't show any signs of my stashes. That's when I went to DuckDuckGo to find out! My search to recover deleted git stash took me to s stackoverflow answer.

The solution was using a git command I was not yet familiar with (but now have a lot more reason to find out more about).

git fsck --no-reflog | awk '/dangling commit/ {print $3}'

The important part was the awk command searching for the "dangling" string along with the --no-reflog.