Logo kepa.eu.org

bfg - git history repo cleaner

Nov 11, 2024 - 1 minute read

preface

Suppose you accidentally committed a 1GB blob file. I assume you are using Git Large File Storage (LFS). Even after removing it from your local repository, it still persists in your .git history. How can you permanently remove it?

To learn more about the bfg tool, use this link.

steps

First check current status.

Then, if you remove a file locally, it will still appear in the Git object history under .git/objects

In the picture below, we can see the complete tree with sizes in MB.

du -sm ./*

pic

solution

git rm --cached GIANT_FILE              # remove blob
bfg --strip-blobs-bigger-than 500M .    # the . indicates local folder
git reflog expire --expire=now --all \
&& git gc --prune=now --aggressive      # manage reference logs and cleanup
git push --force                        # force is optional

Double check

du -sm ./*

pic2