Skip to content

Instantly share code, notes, and snippets.

@ressl
Last active November 27, 2018 21:01
Show Gist options
  • Save ressl/52ce85e7dfa4a49b37405b515d0755f5 to your computer and use it in GitHub Desktop.
Save ressl/52ce85e7dfa4a49b37405b515d0755f5 to your computer and use it in GitHub Desktop.
Cleanup git repo and resign commits
# test before
git log -S'password' -p
# create a password list
echo 'example_password' > passwords.txt
# https://rtyley.github.io/bfg-repo-cleaner/
# replace text
java -jar bfg.jar --replace-text passwords.txt git_project
# delete files
java -jar bfg.jar --delete-files file_name git_project
# cleanup
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# delete old refs
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# resigned tags
git filter-branch --tag-name-filter 'if [ "$GIT_COMMITTER_EMAIL" = "email address" ];
then git commit-tree -S "$@";
else git commit-tree "$@";
fi' -- --all
# delete old refs
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# resigned commits
git filter-branch --commit-filter 'if [ "$GIT_COMMITTER_EMAIL" = "email address" ];
then git commit-tree -S "$@";
else git commit-tree "$@";
fi' -- --all
# delete old refs
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# cleanup
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# test after
git log -S'password' -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment