Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove a big file wrongly committed in git [duplicate]

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?

like image 639
Rodrigo Avatar asked Nov 10 '11 16:11

Rodrigo


People also ask

How do I remove unnecessary files from a git commit?

If this is your last commit and you want to completely delete the file from your local and the remote repository, you can: remove the file git rm <file> commit with amend flag: git commit --amend.


2 Answers

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

like image 73
Leo Avatar answered Sep 23 '22 06:09

Leo


The command you are looking for is filter-branch. It allows you to permanently remove files from an enlistment. This blog has a great tutorial on how to remove problematic files from the repository

  • http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-a-git-repository
like image 35
JaredPar Avatar answered Sep 19 '22 06:09

JaredPar