Recovering stashes that were cleared/dropped erroneously
If you mistakenly drop or clear stashes, they cannot be recovered through the normal safety mechanisms. However, you can try the following incantation to get a list of stashes that are still in your repository, but not reachable any more:
I also deleted a stash, but using the GitKraken gui, so I don't know exactly what git commands it executed. The chosen answer didn't work for me but put me on the right path at least.
In my case, manually searching through --unreachable objects worked. I'm sure there is a more efficient way, but I'm just glad I was able to recover the changes.
ids=`git fsck --unreachable | grep blob | cut -d ' ' -f3`
number_of_ids=`echo $ids | wc -l | tr -d '[:space:]'`
for i in {1..$number_of_ids}; do git show `echo $ids | sed -n ${i}p` > evaluate$i.rb;done;
So this saves all the unreachable objects to files prefixed by "evaluate". I then opened all the files in a text editor (sublime for me subl evaluate*), and evaluated each file in turn, manually copying and pasting the file into the old version of the original file if it was a file from the stash I deleted.
Tips:
Change the .rb to match the file extension of the files you are looking for, to get appropriate syntax highlighting if you want it.
If your files aren't included, you can widen the scope of your search by removing the | grep blob (the blobs were where I found my files).
All of the above answers end with a git stash apply [commit] which is good, but is not an exact undo of git stash clear. For that you need to re-stash the orphaned stash-commit. I found these instructions which almost worked but needed a flag to get all the way there. Summarizing:
Right click on your project in project structure on the left. then select Local History --> Show History
check the screen shot.it shows the list of Local Changes left side you can see the corresponding changes at right side.
To apply changes right click on the selected item it gives two options
1)Revert
2)Create Pacth