Remove large file from several commits ago (in git)

Solution 1:

Read here about filter-branch.

Someone accidentally commits a huge binary file with a thoughtless git add ., and you want to remove it everywhere. Perhaps you accidentally committed a file that contained a password, and you want to make your project open source. filter-branch is the tool you probably want to use to scrub your entire history. To remove a file named passwords.txt from your entire history, you can use the --tree-filter option to filter-branch:

$ git filter-branch --tree-filter 'rm -f passwords.txt' HEAD
Rewrite 6b9b3cf04e7c5686a9cb838c3f36a8cb6a0fc2bd (21/21)
Ref 'refs/heads/master' was rewritten

You can also do an interactive rebase onto your branch at the point where you commited those files, and remove them from that commit. The link above also explains this, but basically:

git rebase -i HEAD~X

will allow you to edit the last X commits.