photo credit: Éole via photopin cc

Remove cached files in your Git history

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:

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?

2 thoughts on “Remove cached files in your Git history”

  1. marcobax22 says:

    Thanks for sharing, very helpful!

    1. Giel Berkers says:

      Yeah, I was really breaking my head in this one!

Leave a Reply