Purge Git History
Use the information in this document to delete content from git repositories and purge them from commit histories. This is useful in the following situations:
- Removing large files that accidentally got committed.
- Removing sensitive content, such as private/secret keys, that got committed.
Prerequisites
- Java
- BFG Repo Cleaner
BFG Installation
- Download the latest BFG jar from the above link.
- Save it to a common folder such as C:\bfg\
- optionally create a script and add it to your path variable
- Create an empty text file named bfg.cmd
- Add the line:
java -jar C:\bfg\bfg-1.14.0.jar %* - Save and close the cmd file.
- Add
C:\bfgto your system PATH variable.
Steps to Purge Strings
- Ensure you meet the prerequisites above.
- Navigate to the offending repository.
- Create a text file where each line consists of the string(s) you wish to purge.
- From command line, run the command:
bfg --replace-text to_remove.txt . - Run the command
git reflog expire --expire=now --all && git gc --prune=now --aggressive - Then finally push the changes with
git push