So today I stumbled upon an issue where I was unable to remove a chunk of code that was left in my repository for some reason. I accidentally added a 1.2 Gib database dump and after I removed it from my repository and git rm –cached it, Git would still try to to push this huge file to my remote, because it was in the history.
So it turned out I had to use git-filter-branch to remove this file completely from my repository. As a reminder for me and as a tip for you here is a single-liner on how to remove cached files from your Git history:
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch your_filename_here' --prune-empty -- --all
Just replace your_filename_here with the file (or pattern) you want to remove from your history and you’re all set.
Visitors give this article an average rating of 4.0 out of 5.
How would you rate this article?
★ ★ ★ ★ ★