HowTo completely remove a file from Git history | MDLog:/sysadmin
http://www.ducea.com/2012/02/07/howto-completely-remove-a-file-from-git-history/
october 2012 ‧ git ‧ open in karakeep
Karakeep has no AI summary for this page yet. summarize now
I just started working on a new project and as you would expect one of the first things I did was to download its git repository from github. These were just some scripts and should have been very small ~5M, but the clone from gitbhub took about one hour as the full repo folder was 1.5G… (with the biggest size under .git/objects/pack) Crazy… What was in the git repository history that would cause something like this? I assumed that at some point in time the repository was much bigger (probably from some file/s that don’t exist anymore), but how could I find out what were those files? And more important howto remove them from history? Well if you came here from a google search on “how to remove a file from git history” then you probably know there are plenty of docs and howtos on how to achieve this but from my experience none of them really worked. This is why I decided to document the steps needed to identify the file from the git repo history that is using all that space and to have it removed fully and bring the repository to a manageable size.
First we need to identify the file that is causing this issue; and for this we will verify all the packed objects and look for the biggest ones:
git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -5
(and grab the revisions with the biggest files). Then find the name of the files in those revisions:
git rev-list --objects --all | grep <revision_id>
Next, remove the file from all revisions:
git filter-branch --index-filter ‘git rm --cached --ignore-unmatch <filename>’
rm -rf .git/refs/original/
Edit .git/packed-refs and remove/comment any external pack-refs. Without this the cleanup might not work. I my case I had refs/remotes/origin/master and some others branches.
vim .git/packed-refs
Finally repack and cleanup and remove those objects:
git reflog expire --all --expire-unreachable=0
git repack -A -d
git prune
Hopefully these steps will help you completely remove those un-wanted files from your git history. Let me know if you have any problems after following these simple steps.
*bookmark *download *tobuy *tofollow 2d 360 3d abandonware actionscript air algorithm android api app apple appstore arcade arduino art article asm audio automation backlight backup berlin bitcoin blipfm blipster blog bluetooth book bookmark bootcamp brasil bug c c# c++ carro casa chiptune cocoa cocoa-touch code collection component controller css database debug demoscene design deutschland dev diy doc dos dosbox dotnet download electronics emu emudev emulator example famicom feedbin fix flash flex forum freeware gadget game gameboy gamedev germany git GoogleReader hack hacks hardware home home-automation homebrew howto htpc http IFTTT image imported inspiration ios ipad iphone iso itunes jailbreak japan java javascript lcd lib library linux mac mame math mce mediacenter megadrive midi mod mp3 mpd music mythtv nas nes objective-c opengl opensource osx pc piracy plex plugin Pocket ps2 ps3 pvr raspberrypi recipe remote repro resource retrogaming retropc rgb roms rubyonrails saopaulo sdk shmups shop shopping sms snes software soundblaster source star svn swift synology synth terminal tips tool toread torrent travel tutorial twitter ubuntu ui uitableview unix unlock veralite viagem vista vpn vps walkthrough warez web2.0 webservices wii windows wishlist wordpress xbmc xbox xcode xna z80