Kevin Ferrell

git

How To Permanently Remove Files From Git

I’ve been using git as my source control system of choice for the past year or so now. We use it within the government agency I work at for all of our mobile projects because our development laptops are often offline and we need to be able to branch and commit changes to our local repos while we’re offline. Git is great for this type of setup!

I recently downloaded the latest build of the excellent PSPDFKit library that we’re using in one of our projects for document viewing. I copied the new build into my XCode project, performed some regression testing, and committed the changes. Success! Except that somehow during this process I had actually copied my entire Downloads directory into my XCode project folder and committed it to my local git repo. This increased my repo size to around 2GB! I then deleted the folder and committed the delete but of course the folder and its contents was still in the repo’s history.

Luckily I was able to find this great post on Dalibor Nasevic’s blog that describes how to permanently remove the files and folder from git:

git filter-branch –tree-filter ‘rm -rf AwesomeProject/Downloads’ HEAD

It looks like the filter-branch command has some cool options for specifying a range of commits to perform actions on as well. Once I ran this I was able to push my local branch to the master and was all set. I hope this tidbit helps someone else out as much as it helped me!

Discussion Closed

New comments are not allowed on this post.