Hacker News new | ask | show | jobs
by ww520 4408 days ago
Can you elaborate what the command is? I would be really happy to learn about it. I know the complicate way to do it. Just want an easier way to do it, rather than multiple steps.

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
1 comments

You already seem to know about filter-branch, but:

    git filter-branch --tree-filter 'rm -f path/to/bigfile.zip'
is one command.
Thanks! I would have tried to muddle through with rebase.

It may be obvious that this solution is also going to cause the same issue as with rebasing, but just in case, from the man page for filter-branch:

WARNING! The rewritten history will have different object names for all the objects and will not converge with the original branch. You will not be able to easily push and distribute the rewritten branch on top of the original branch. Please do not use this command if you do not know the full implications, and avoid using it anyway, if a simple single commit would suffice to fix your problem. (See the "RECOVERING FROM UPSTREAM REBASE" section in git-rebase(1) for further information about rewriting published history.)

Thanks for the info.