git filter branch to undo a blob push that exceed the limits
How to use filter branch to revert a gitlab push quota
commit blob file which exceed the 100MiB limit
If you commit a blob in your working directory and realise that it could not be pushed to the remote, unless you pay for the tier wich permit transfer over 300mb each, then you have to play with filter-branch. You’v got here the explaination.
let’s say you tried to push a tarball containing all the lfs 12.3 packages which mean you try to push more than 530Mb to gitlab.com. You first add and commit with a nice messaage, and try a git push on your gitlab.com remote reposiotry. Then you will receive a message like :
git push
Enumerating objects: 60, done.
Counting objects: 100% (60/60), done.
Delta compression using up to 16 threads
Compressing objects: 100% (28/28), done.
Writing objects: 100% (45/45), 528.95 MiB | 10.62 MiB/s, done.
Total 45 (delta 13), reused 38 (delta 6), pack-reused 0 (from 0)
remote: GitLab: You are attempting to check in one or more blobs which exceed the 100.0MiB limit:
remote:
remote: - a64048a0811f4514ab2fdfaabe06fa4369bed557 (529 MiB)
remote:
remote: To resolve this error, you must either reduce the size of the above blobs, or utilize LFS.
remote: You may use "git ls-tree -r HEAD | grep $BLOB_ID" to see the file path.
remote:
remote: Please refer to https://gitlab.com/help/user/free_push_limit.md and
remote: https://gitlab.com/help/administration/settings/account_and_limit_settings.md for further information.
To gitlab.com:fredmj/lfsgoldimage.git
So you try to remove the offending blob with a rm -f data/lfs/12.3/lfs-packages-12.3.tar and push again. But no, obviously your blob is still in the history.
So as well explained in stackoverflow message referenced up, you should do sucessively some actions to repair the mess. That consist into filtering the removed files on your local branch and garbage it before pushing.
git filter-branch --tree-filter 'rm -f data/lfs/12.3/lfs-packages-12.3.tar'
WARNING: git-filter-branch has a glut of gotchas generating mangled history
rewrites. Hit Ctrl-C before proceeding to abort, then use an
alternative filtering tool such as 'git filter-repo'
(https://github.com/newren/git-filter-repo/) instead. See the
filter-branch manual page for more details; to squelch this warning,
set FILTER_BRANCH_SQUELCH_WARNING=1.
Proceeding with filter-branch...
Rewrite 3a0464a8a25c5329856683f915a9ea554a122738 (95/95) (4 seconds passed, remaining 0 predicted)
Ref 'refs/heads/desktop' was rewritten
to remove the file itslef. Note the rm -f ... even if the file is already remove by hand -ie with a git rm- as explained in the doc. \
Then you could call the git garbage collector
git gc
Enumerating objects: 604, done.
Counting objects: 100% (604/604), done.
Delta compression using up to 16 threads
Compressing objects: 100% (275/275), done.
Writing objects: 100% (604/604), done.
Total 604 (delta 252), reused 599 (delta 248), pack-reused 0 (from 0)
Enumerating cruft objects: 2, done.
Traversing cruft objects: 2, done.
Counting objects: 100% (2/2), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), done.
Total 2 (delta 0), reused 2 (delta 0), pack-reused 0 (from 0)
and finally push your code
git gc
Enumerating objects: 604, done.
Counting objects: 100% (604/604), done.
Delta compression using up to 16 threads
Compressing objects: 100% (275/275), done.
Writing objects: 100% (604/604), done.
Total 604 (delta 252), reused 599 (delta 248), pack-reused 0 (from 0)
Enumerating cruft objects: 2, done.
Traversing cruft objects: 2, done.
Counting objects: 100% (2/2), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), done.
Total 2 (delta 0), reused 2 (delta 0), pack-reused 0 (from 0)
To avoid such a work, next time you will surely use a pre-commit hook.