一同事使用sourcetree操作stash 时误将未提交的stash 全部删除了。求助于我,我也没经历过,全网找了下,使用下面的方法找回了代码。记录一下。

以下为stackoverflow原回答:

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