Search code examples
gitgit-rewrite-history

How do I remove a big file wrongly committed in git


Possible Duplicate:
How to purge a huge file from commits history in Git?

I did a stupid thing. Imagine that I committed a 100MB file. Then I see this and delete this file and commit again. This is a normal procedure to delete a file.

But now the side effect is that my history is heavy because it's saved this large file (I believe this is why it is heavy). I am only using local git, so I do not synchronize in any server.

How can I definitively remove this file and save disk space?


Solution

  • You can do it using the git filter-branch command, like this :

    git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch path_to_file" HEAD
    

    You can find more documentation here http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-a-git-repository