Web Development

Git – How to Remove a Large File from a Repository?

Git push hung every time at writing objects without any errors. After being patient with the uploading, I received this error:
$ git push -u origin mq_ernst_changes
Counting objects: 309, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (309/309), done.
Writing objects: 37% (117/309), 22.21 MiB | 6.00 KiB/s
Writing objects: 37% (117/309), 93.24 MiB | 77.00 KiB/s
Writing objects: 37% (117/309), 93.88 MiB | 81.00 KiB/s
Writing objects: 100% (309/309), 99.19 MiB | 66.00 KiB/s, done.
Total 309 (delta 245), reused 0 (delta 0)
remote: error: GH001: Large files detected. You may want to try Git Large File Storage – https://git-lfs.github.com.
remote: error: Trace: 8fe6f8022e5f5776fabfd5929071b90e
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File wp-content/uploads.tar is 103.52 MB; this exceeds GitHub’s file size limit of 100.00 MB
To git@github.com:e7gezly-organization/wordpress.git
! [remote rejected] mq_ernst_changes -> mq_ernst_changes (pre-receive hook declined)
error: failed to push some refs to ‘git@github.com:e7gezly-organization/wordpress.git’

After a little googling on Stack Overflow, this answer was very helpful. It referred me to the official Git documentation under Removing Objects Section.

I found it worth sharing with you folks to save you a few head scratches for the same issue;

git gc
git count-objects -v
git verify-pack -v .git/objects/pack/pack-0f10041478ef7ed93fa7195af7a5a39f5865243d.idx  | sort -k 3 -n   | tail -3
git rev-list --objects --all | grep d65e8e7
git log --oneline --branches -- wp-content/uploads.tar
git filter-branch --index-filter 'git rm --ignore-unmatch --cached wp-content/uploads.tar' -- 178a401^..
rm -Rf .git/refs/original
rm -Rf .git/logs/
git gc
git count-objects -v
git prune --expire now
git count-objects -v

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.)


[1] http://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery#Removing-Objects

[2] http://stackoverflow.com/questions/8740187/git-how-to-remove-file-from-historical-commit

[3] https://asciinema.org/a/1euph7hu99240bwsspwgs8bgu


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s