Skip to content

rewriting Git history


This tip involves a lot of risky actions I do not fully understand. Use at your own risk.

Use java -jar bfg-1.13.0.jar --no-blob-protection --replace-text "/foo/bar/baz/", where is a text file containing a list of lines of text to be removed, and /foo/bar/baz/ is the directory where the Git repository is stored.


By default, BFG Repo-Cleaner protects HEAD from being modified, so --no-blob-protection is added to prevent this.


By default, BFG Repo-Cleaner replaces the text lines with **REMOVED**, so append ==> to a line to replace it with an empty string.

Then, cd into the directory where the Git repository is stored and use git reflog expire --expire=now --all && git gc --prune=now --aggressive. Push to remote with git push foobar --force --all and git push foobar --force --tags, where foobar is the shortname of the remote.

Optionally, then use git commit --dry-run to check for local changes and git stash --include-untracked && git stash drop to discard them.


No rights reserved: CC0 1.0.

prior work