Retrieve deleted stash in Git using SourceTree

Based on previous 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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)