Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Retrieve a deleted stash

Tushar Mathur
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 18, 2013

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

7 answers

1 accepted

30 votes
Answer accepted
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 21, 2013

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.

Tushar Mathur
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 21, 2013

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

John Fitzsimmons
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 15, 2014

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

Like gutkol likes this
sujit yadawad
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 7, 2015

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

Louis Parsonson
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 5, 2016

You sir, are my hero, thank you!

Phung Lam
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 26, 2016

You make my day sir, thanks a lot

Kavya Rani January 31, 2017

Day saver. Thank you so much.

Deleted user March 9, 2018

Thank you!! Almost lost a day of work :) 

anirudh reddy
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 30, 2018

How to retrieve :

git fsck --no-reflog | awk '/dangling commit/ {print $3}' | xargs git show > dangles.txt

search and select the commit you want and do below
git stash apply dec98ac9eb98abf94f43beecdf07f9c17e678ce1;
Like # people like this
addym55
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 13, 2018

God bless u man, Thanks a lot 

Jan Maške
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 25, 2018

Thanks alot :)

MVarga12
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 25, 2018

Just saved my bacon, thank you.

Madhu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 19, 2018

This was a life-saver ! Thanks !

respawned
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 23, 2018

Thank you so much for this answer!
This just saved me from a lot of headache.

It took a while for me to find the right commit, but I found it in the end. :)

exellionNET
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 9, 2018

Thank you very much! You saved day of my work!

Musat Bogdan Ionut
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 31, 2018

Thank you, sir!

Levi Crain
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 15, 2019

You Sir are a life saver.

John Okoroafor
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 4, 2019

Really Helpful. Thanks Alot.

Aya Akl
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 11, 2019

@anirudh reddy you saved my life today with your solution!!!! thanks a million

Milenko Brkovic
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 11, 2019

Thanks! Helped me a lot!!!!!

BertrandBucher
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 20, 2020

This saved my day ! Thank you !!

gutkol
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 5, 2020

Thank you so much. Same problem I had today. For mistake I clicked delete stash and this answer helped me a lot!

RCBryank
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 28, 2020

Thx a lot!!!!

5 votes
John Opferkuch
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 19, 2018

Brilliant!  This outputs the details to a file so you can search for whatever you may have accidentally nuked. 

git fsck --no-reflog | awk '/dangling commit/ {print $3}' | xargs git show > dangles.txt

anirudh reddy
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 30, 2018

How to retrieve :

git fsck --no-reflog | awk '/dangling commit/ {print $3}' | xargs git show > dangles.txt

search and select the commit you want and do below
git stash apply dec98ac9eb98abf94f43beecdf07f9c17e678ce1;.



Like # people like this
0 votes
kevinfarel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 29, 2020

♡^▽^♡

♡^▽^♡

♡^▽^♡

♡^▽^♡

♡^▽^♡

♡^▽^♡

♡^▽^♡

0 votes
JHidalgo
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 14, 2019

Thanks you for this! It saved my life!

0 votes
William McKeand
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 14, 2019

Thank you!

0 votes
aryapratik7
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 27, 2019

Thanks a lot for this. Saved my day.

0 votes
Jake Blackwell
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 24, 2018

Thank you for this so much!

Asad Abbas
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 31, 2019

thanks

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events