Skip to content

Instantly share code, notes, and snippets.

@andykingking
Created October 23, 2013 11:58
Show Gist options
  • Save andykingking/7117273 to your computer and use it in GitHub Desktop.
Save andykingking/7117273 to your computer and use it in GitHub Desktop.
Accidentally `git reset --hard`? Get em all back
#!/bin/bash
# output all files in index that haven't been garbage collected
git fsck --cache --unreachable $(git for-each-ref --format="%(objectname)") > badfiles
# output all files by showing them via sub-hash
FILENUM=1
cat badfiles | cut -c 18-24 | while read cur
do
git show $cur > $FILENUM
let "FILENUM += 1"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment