Last active
November 28, 2023 15:00
-
-
Save pravynandas/f6e7d5ffb3ba21fa1d33f2c6f9578ef0 to your computer and use it in GitHub Desktop.
Delete files with secrets in git history - github
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/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