Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: erase files from repository from previous commits

Tags:

git

github

I am on github. I set up a .gitignore file in which I specify files not to be added to future commits since I'm trying to lighten the cloning. Now I need to delete all those .class files for example from all the previous commits to share only the necessary sources, otherwise no matter my efforts it will always weight 50mb more or less. I had a look on http://cheat.errtheblog.com/s/git I think I might need a composition of those command but I really don't wanna s***w up my work. thanks

like image 795
urobo Avatar asked Dec 22 '22 22:12

urobo


1 Answers

There is an example in the git-filter-branch docs which matches your use case.

git clone project project.tmp
cd project.tmp
git filter-branch --prune-empty --index-filter 'git rm --cached --ignore-unmatch *.class' HEAD 
cd ..
git clone project.tmp project.clean
rm -rf project.tmp
cd project.clean

project.clean should then be ready to be pushed upstream.

PS. If you are nervous about how this operation might go, it never hurts to experiment on a clone and github test branch.

like image 62
unutbu Avatar answered Jan 15 '23 13:01

unutbu