Retrieve a deleted stash

I deleted the stash while applying. And then by mistake reverted everything. How can I get it back? Please help.

1 answer

1 accepted

Unless you have a backup somewhere else, this is difficult. However stashes are stored as regular git objects and provided this was done recently then the commit object will still be there and not garbage collected yet, it just won't have any references to it.

You can list all unreachable commits , but you have to drop to the command line (click Terminal on the toolbar). Then type:

git fsck --unreachable

This will show you all the commits which are not reachable by a branch / tag and which haven't been garbage collected yet. Look for the ones that say 'unreachable commit', ignore the blobs. The chances are it will be the one closest the top, unless you've performed some other actions which created more unreachables. You can examine the commits by doing 'git show <sha>', and this should identify the stash, it'll probably be called 'On master: <your comment>' or similar. Once you've found it, copy the SHA.

To recover this you then do:

git stash apply &lt;sha&gt;

Which will bring it back into your working copy.

Going through each commit through the terminal is quite combersome. But atleast there is a solution. Thanks :)

Very helpful. Just used this to help out a co-worker. Thank you! :-)

Worked like a charm.. Thanks a lot saved my 4 hours of work.. :)

You sir, are my hero, thank you!

You make my day sir, thanks a lot

Day saver. Thank you so much.

Suggest an answer

Log in or Join to answer
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

229 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot