2

I have an incubator directory right at the top of my git repo and I'd like to completely remove it from history. I've tried:

git filter-branch --force --tree-filter "rm -rf incubator/" --prune-empty HEAD

And:

git filter-branch --force --index-filter "git rm --cached -r -f --ignore-unmatch incubator" --prune-empty

But none of them worked.

Am I doing something wrong here? Is there a way I can see what is going on or why this directory is not being removed?

Roberto Tyley
  • 24,513
  • 11
  • 72
  • 101
MaurĂ­cio Linhares
  • 39,901
  • 14
  • 121
  • 158

1 Answers1

1

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.

Community
  • 1
  • 1
Roberto Tyley
  • 24,513
  • 11
  • 72
  • 101