I am using source tree. I had created a stash of multiple changes and by mistake deleted it. Is there a way to retrieve them back?
Based on the above answers, here is a simple sequence:
Open a terminal window and cd into a folder under the repository. Then:
git fsck | awk '{print $3}' > tmp.txt cat tmp.txt | xargs git show > tmp2.txt
Now open tmp2.txt in editor, locate your lost code, and find the commit-id on top of it. Then apply the code:
git stash apply <commit id> rm tmp.txt tmp2.txt
This saved my life! I really thank all those who answered this question. I bless the git creator Linus Torvalds for keeping deleted stuff in the git database. Genius!!
EDIT 2021: note that Windows users can do the same using Git Bash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With