Sometimes you end up stashing code, then at some point those stashes get cleaned. And one day, you may encounter the situation I faced this week:
Fine, this code is merged, so let’s delete the related stashes. Done! And… hey… wasn’t this part of the feature supposed to be in the codebase? Is the stash I just deleted lost forever?
Fortunately, I managed to recover lost stashes. I’m not a Git expert, but here’s what worked for me after going through various readings (including some Stack Overflow answers).
Here’s the two-steps recovery procedure.
1. List lost stashes
Let’s run this command for a project where all stashes were trashed:
git fsck --unreachable | grep commit | cut -d ' ' -f3 | xargs git log --merges --no-walk
It returns a list of lost stashes, ordered by date.

- To quit the list of stashes, press the Q key.
- To navigate in a long stashes list, use
upanddownarrows. - For Windows user, maybe johnwait’s comment will help you during the battle.
2. Send a lost stash back where it comes from
Let’s use the commit hash of the second stash:
git update-ref refs/stash 4b3fc45c94caadcc87d783064624585c194f4be8 -m "My recovered stash"
And that’s it! You’ll find your stash as usual, using git stash list or by having a look in your favorite Git client.
Gotchas
1. I still can’t see my recovered stash
Retry using the --create-reflog parameter (thanks studoggithub):
git update-ref refs/stash 4b3fc45c94caadcc87d783064624585c194f4be8 --create-reflog -m "My recovered stash"
2. My Git isn’t in English
If your Git isn’t in English, you’ll have to run alias git='LANG=en_GB git' each time you want to recover a set of stashes (thanks mathieuschopfer).
Some advices
Commit messages are healthy
Always use a commit message using git stash save -m "My commit message": without message, the only informations helping to identify a stash are its timestamp and the branch it was saved from, which may not be enough compared to a strong explicit name.
Commit messages also help Git clients:
- GitUp, the Git client I use, completely fails at showing unnamed stashes. That’s probably why you can’t create a stash in GitUp without giving it a name, which is great!
- The well-known SourceTree succeeds at showing unnamed stashes, but as you can guess, the list isn’t friendly to browse:
Yes, git stash apply > git stash pop
Unlike git stash pop, git stash apply does not remove the stash from the list of stashes, which can avoid some loss.
Branches > stashes
Finally, I’d recommend to avoid git stash. Instead, try to use a branch. This seems obvious but it only comes to me as I was finding a way to recover a stash: maybe I should use temporary branches instead of stashes. Using the Git Flow method at work, this could have come to my mind before encountering a painful experience.
If you have any stash hint or experience that you want to share, comments are welcome.
Latest comments (26)
It was incredibly helpful — it saved me an entire month’s worth of work!
Saved my day ❤️
Mehdi bro you have no idea how big of a trouble you saved me from. I accidentally stashed and cleared hard work of my several days and night (My mistake I shouldn't have piled up that big). And your post just saved my life. I was almost crying. Thanks a lot dude. God bless you.
Hey Samar, you know what? I feel there's a lot of gratitude in your message, so I want to say thank you for having taken the time to put it down. It sincerely made my day better (and today is not the easiest one for me 😅).
I hope everything's fine with your work, now. Sharing is caring. ✌️
Thanks!!
It is good to know, after the fist command, pick your hash and use:
$ git stash apply e3cf5932f4816f5b0022190ce6b871f51cf882de
It worked for me
Thanks, it saved my day !!
Thanks, i got my changes back while my rebase autostash failed
Thanks a lot. This saved me .
Thanks a lot lot lot lot lot lot. You saved my time and I recovered 70 - 80 percent of my work :)
This was extremely helpful. Thank you for sharing your knowledge!
saved my butt! thanks!