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 *todownload *tofollow *toread *towatch *wishlist 2d 360 3d 3ds 3g 8080 abandonware accounting actionscript adapter addin adhoc adventure air airbnb airplay alemanha algorithm android animation api app apple appletv appstore arcade architecture archive arduino aria2 art article asm assembler atcommand audio autolayout automation aws baby backend backlight backup bank bbs beer berlin bezier bios bitcoin bivert blipfm blipster blog blu-ray bluetooth bluray bonjour book bookmark bootcamp boxee brasil brazil breaks bruno bug bugtracking build buildapc business c c# c++ canada capacitors car carro casa case cave cdx cell chart cheat chiptune cliq cms cocoa cocoa-touch code codec collection component console control controller cookie cooking cooler core-animation core-audio core-data core-graphics coreaudio corporate couchpotato course covid crack crt crypto css cubic-bezier curitiba curso cv cydia database dataservices ddwrt debug decompiler deconz degrafa demoscene design designpatterns designsystem deutsch deutschland dev developer development disassemly diy dj dlna dns dnsmasq doc docker docs documentation dos dosbox dotnet download dreamcast drink driver drm ds ds-lite dvb-c dvd ebook electronics emu emudev emulator engine entrepreneurship epg eprom epub erp example exploit facebook famicom faq feedbin fightstick figma filetype:pdf finances firebird firetv firmware fix flash flashcart flex flexvizgraphlib fluorine fm font forum framework free freelance freeware gabinete gadget game gameboy gameboy-pocket gamecube gamedesign gamedev gamegear gamegenie games gba gdb genesis german germany ghidra git gnu google googlemaps GoogleReader gps gpu graph gsm gui guide hack hackintosh hacks hamburg hardware harmony hassio hd hdmi hdpvr health healthinsurance home home-automation homeassistant homebrew honda hosting hotel howto html htpc http icecast icon IFTTT ikea im image imported indie indiegame info inspiration install insteon internet interview investimento ios ios7 ipad iphone ipod iptv ir irblaster irpf isdb iso itunes j2me jailbreak jantar japan java javascript job json keyboard kodi language last.fm lastfm lcd learning lg lib library light linux liquidsoap live lldb localization london lua mac macos make mame management manual mapkit maps mastersystem math mce media media:document mediacenter mediaserver megadrive memory-management memorycard miami microsim midi mister mms mobile mobilesubstrate mod modchip models modem monitor monogame mopidy motorola movie movies mp3 mpd msn mtu multiroom music mysql mythtv nas nds neogeo nes net network nointro nvidia nyc objective-c opcode openal opengl opengles opensource openvpn opl os osx pal paper parts pc pcb pcengine pci perlerbeads peugeot phone photo photoshop php physics pico8 piracy plex plugin Pocket pokemon portfolio poster prepaid profiling project protocol provisioning proxy ps1 ps2 ps3 ps4 psp puremvc push pvm pvr python raspberrypi rc recalbox receita recipe recover redump regex region regionlock remote repair repro research resource restaurante retrogaming retrograming retropc retropie retroprogramming review rgb rip riser rockband rom romhack roms router rpg rsync ruby rubyonrails sample saopaulo saturn scart scrape script scumm sdk sdl security seedbox serial server service setup shipping shmups shop shopping shoutcast sign silencio sim skinning sms snes softmod software sonos soulseek sound soundblaster soundtrack source specs spline spotify spritekit sql sqlite star startup steamdeck stick store stream subtitles subversion svn swift swiftui swing switch switchless sync synology synth tasker tax tech terminal test tether theme theos thinclient thread threads three20 tickets timezone tips titles tobuy tokyo tool tools toread torrent toy tracker travel trip tshirt tutorial tv tweak twitter ubiquiti ubuntu ui uifont uikit uitableview uiview unity unix unlock upload upnp uremote usa usb utorrent ux veralite viagem video vinyl visa vista visualization visualstudio vita vpn vps vr vst walkthrough wallpaper warez wdtv web web2.0 webdesign webdev webradio webservices wifi wii wiiu windows wishlist wordpress xbla xbmc xbox xbox360 xcode xml xna youtube z-wave z80 zigbee