Skip to content

Instantly share code, notes, and snippets.

@pravynandas
Last active November 28, 2023 15:00
Show Gist options
  • Save pravynandas/f6e7d5ffb3ba21fa1d33f2c6f9578ef0 to your computer and use it in GitHub Desktop.
Save pravynandas/f6e7d5ffb3ba21fa1d33f2c6f9578ef0 to your computer and use it in GitHub Desktop.
Delete files with secrets in git history - github
#!/bin/bash
while read -r line; do
if [[ $line == *"blob id:"* ]]; then
# echo "$line"
arrIN=(${line//:/ })
blobId=${arrIN[4]}
echo "blob id:$blobId"
pathx=$(git rev-list --all --objects | grep $blobId)
# echo "$pathx"
arrPath=(${pathx// / })
path=${arrPath[1]}
echo "path: $path"
# BEWARE!! git filter-repo below command with empty string means wiping off repo.
if [ -n "$path" ]; then
echo "cleaning git history for path: $path"
git filter-repo --invert-paths --path "$path"
fi
fi
done < ./github_rule_output.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment