Last active
July 15, 2022 21:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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