Skip to content

Instantly share code, notes, and snippets.

@jaysoffian
Last active July 15, 2022 21:30
Show Gist options
  • Save jaysoffian/f42f4b1806f65158b404088144fca227 to your computer and use it in GitHub Desktop.
Save jaysoffian/f42f4b1806f65158b404088144fca227 to your computer and use it in GitHub Desktop.
"git lost-and-found" command to help recover objects you added but failed to commit and then deleted by accident
#!/bin/sh
find .git/objects -mtime -2h -type f | while read -r path
do
dir=${path#.git/objects/}
dir=${dir%/*}
name=${path##*/}
id=$dir$name
type=$(git cat-file -t "$id")
if test "$type" = blob
then
echo "$id"
git cat-file -p "$id" | head
echo
echo ========================================
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment