by ww520 · 12y ago · 0 comments
One feature I really hope git to add is an easy way to clean up deleted files in the repository. Some times I accidentally check in some large zip files or built files and that really blows up the repository size. Those files stay in there even if I've deleted them. It's a pain to clean them up.
This was probably complicated by the fact I thought you were saying "the feature is there, go RTFM." This is not a regular feature of Git and I think architecturally it's the wrong idea. You want to delete objects, you better go learn rebase, and be prepared to piss off anyone who already has a clone since you're going to have to break fast-forwarding.
Here are the steps I know of to get rid of big blobs. Long and complicate. Is there a better way?
- Find out size of the big blobs and their HASH.
git verify-pack -v .git\objects\pack\pack-HASH.idx | sort -k3n
- Find out the name of a blob hash to verify the blob is the one to delete.
git ls-tree -r HEAD | grep HASH
git ls-tree -r COMMIT_HASH | grep HASH
git log --all --raw --no-abbrev | grep HASH
- Expire all working reflog now, and then prune deleted blob
git reflog expire --expire=all
git gc --prune=now
- Remove a blob.
git push -force
git filter-branch --index-filter 'git rm --cached *.zip --ignore-unmatch ' HEAD
git filter-branch --index-filter 'git rm --cached *.zip --ignore-unmatch ' --prune-empty -- --all
git filter-branch --index-filter 'git update-index --remove webapp.zip' <introduction-revision-sha1>..HEAD
git filter-branch --index-filter 'git update-index --remove webapp.zip' HASH..HEAD
- Clean up reflogs.
rm -Rf .git/refs/original
git reflog expire --expire=now --all
git gc --aggressive
git prune git filter-branch --tree-filter 'rm -f path/to/bigfile.zip'
is one command.