Git: how to remove file and commit from history
13th February 2009
Once I accidentally added circa 300 MiB of archive files to one of my git repositories (which was as small as 5 MiB). I removed those files as soon as I noticed them, but the .git directory still preserved commits with those files, and still occupied over 300 MiB.
I have found the solution at stackoverflow (see also this question).
This method worked for me, but I couldn’t push my rebased repository to the gitosis. I would need to re-init the gitosis repository from my rebased, but I’m not yet prepared to do that.
There is also a slightly different method (which relies on a temporary tag instead of a temporary branch), documented in Git online manual pages; I prefer the temporary branch method.
Below is a full copy-paste of the winning answer by Charles Bailey:
# create and check out a temporary branch at the location of the bad merge
git checkout -b tmpfix# remove the incorrectly added file
git rm somefile.orig# commit the amended merge
git commit –amend# go back to the master branch
git checkout master# replant the master branch onto the corrected merge
git rebase tmpfix# delete the temporary branch
git branch -d tmpfix
Also, in my case this thread at stackoverflow was highly useful. I start enjoying the concise and compact style of Charles Bailey
:
Read the rest of this entry »
Posted in how-to, Links, Programming | 2 Comments »
