When you run into this problem, git rm
will not suffice, as git remembers that the file existed once in our history, and thus will keep a reference to it.
To make things worse, rebasing is not easy either, because any references to the blob will prevent git garbage collector from cleaning up the space. This includes remote references and reflog references.
I put together git forget-blob
, a little script that tries removing all these references, and then uses git filter-branch to rewrite every commit in the branch.
Once your blob is completely unreferenced, git gc
will get rid of it
The usage is pretty simple git forget-blob file-to-forget
. You can get more info here
I put this together thanks to the answers from Stack Overflow and some blog entries. Credits to them!