- First Go to below website link:
https://rtyley.github.io/bfg-repo-cleaner/
- Download the bfg.jar file.
- Place this file where repo has leaked secrets.
- Execute below command with filename which contain leaked secrets
java -jar bfg-1.14.0.jar .git --delete-files *terraform.tfstate.backup*
- After executing above command, create any empty file to commit new changes in the history to repo.
- This will re-write the history and there won't be any leaked secret keys in the history
Tips:
https://medium.com/@vs28031996/remove-git-history-with-bfg-repo-cleaner-866808826eea
https://stackoverflow.com/questions/49580624/correct-usage-of-bfg-repo-cleaner