Recover a dropped stash in Git

There’s a great thread over on Stack Overflow about how to recover a dropped stash in Git. Here’s a handy little bash script for doing exactly that:

#!/bin/bash
HASHES=`git fsck --no-reflog | awk '/dangling commit/ {print $3}'`
for HASH in $HASHES; do
	clear
	echo $HASH
	echo
	git show $HASH
done

After you have the SHA hash of the stash in question, you can apply it easily with:

git stash apply <SHA>

Leave A Comment