Skip to content

Instantly share code, notes, and snippets.

@dwisiswant0
Created July 2, 2025 12:33
Show Gist options
  • Save dwisiswant0/3159052420f2f4e54500578cba242983 to your computer and use it in GitHub Desktop.
Save dwisiswant0/3159052420f2f4e54500578cba242983 to your computer and use it in GitHub Desktop.
gitleaks-unreachable-commits
#!/bin/bash
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
echo "This is not a git repo."
exit 1
fi
git fsck --full --no-reflogs --unreachable |
grep 'unreachable commit' |
awk '{print $3}' |
while read commit; do
GITLEAKS="$(git show ${commit} | gitleaks stdin -v 2>/dev/null)"
if [ $? -eq 1 ]; then
echo "${commit}"
echo "${GITLEAKS}"
echo "---------------------------------"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment