Skip to content

Instantly share code, notes, and snippets.

@Bradshaw
Created June 15, 2021 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bradshaw/7ff835ab7108ac17732841eb2261a925 to your computer and use it in GitHub Desktop.
Save Bradshaw/7ff835ab7108ac17732841eb2261a925 to your computer and use it in GitHub Desktop.
List lost and found commits with a one-liner hash, relative date and commit message
#!/bin/bash
# Saves your life if you accidentally deleted a branch
regex="commit (.*)"
git fsck --lost-found | while read f; # unquoted in order to allow the glob to expand
do
if [[ $f =~ $regex ]]
then
hash="${BASH_REMATCH[1]}";
echo $(git log --format="%h: %ar - %s" -n 1 $hash)
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment