Rewriting Git history is a tricky process and git-filter-branch
doesn't make it easy (see below), so instead use the BFG, a simpler, faster alternative to git-filter-branch
, specifically designed for removing unwanted files from Git history.
Carefully follow the BFG's usage instructions - the core part is just this:
$ java -jar bfg.jar --delete-folders incubator my-repo.git
Any folder named incubator
(that isn't in your latest commit) will be removed from your Git repository's history. You can then use git gc
to clean away the dead data:
$ git gc --prune=now --aggressive
The BFG is typically at least 10-720x faster than running git-filter-branch
, and generally easier to use.
...diagnosing the git filter-branch failure?
Because (as mentioned above) rewriting Git history is a complicated business, there are lots of ways it can go wrong, so you might need to add more detail to where you say "But none of them worked" in your question. The git filter-branch
incantation you use looks like it would do something - it would delete the incubator
folder from your master branch - so did it at least do that? Perhaps you wanted it to delete from other branches, in which case you need to add the --all
flag, or perhaps you wanted it removed from tagged commits as well, which would require --tag-name-filter cat
. More details: https://stackoverflow.com/a/21023615/438886
Plenty more things can go wrong, you're better off using BFG if you can.
Full disclosure: I'm the author of the BFG Repo-Cleaner.