How to remove a file at the origin of multiple branches from the git history?

296 views Asked by At

I have a large file that was committed at the origin of multiple branches. This file was later modified, moved or removed from the branches. The problem is that the file is too big for GitHub, so I want to remove it (all versions of it) from everywhere. How can this be done?

I have seen a recipe for amending a merge containing such a file (https://stackoverflow.com/a/308684/42973), or a method for removing a file from (apparently) a single branch (https://stackoverflow.com/a/5563603/42973), but they do not apply or work in this case.

1

There are 1 answers

0
Roberto Tyley On BEST ANSWER

Use the BFG Repo-Cleaner, a simpler, faster alternative to git-filter-branch specifically designed for removing unwanted files from Git history.

You should carefully follow the usage instructions, but the core part is just this:

$ java -jar bfg.jar  --strip-blobs-bigger-than 50M  my-repo.git

Any files over 50MB in size (that aren't in your latest commit) will be removed from your Git repository's history.

The BFG is typically at least 10-50x faster than running git-filter-branch, and generally easier to use.

Full disclosure: I'm the author of the BFG Repo-Cleaner.