突然发现git项目往github上push时,push不上去,报错:
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: eeae3313e0b59e20bfec98b8193936ba72d1630f495a8fd6c79a522423323
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File shared/log/cron.log is 577.65 MB; this exceeds GitHub's file size limit of 100.00 MB
To github.com:xxxx/xxxx.git
! [remote rejected] develop -> develop (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:xxxx/xxxx.git'
错误中提示shared/log/cron.log
文件太大,超过100MB的限制,而无法提交,寻找了一下这个文件,发现已经被删除,但是commit中还是有此文件的提交记录。
查看git历史中大文件命令:
git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -5 | awk '{print$1}')"
查看.git
目录大小命令:
du -sh .git
刚开始使用了 git filter-branch
命令去做,有两万多个commit,发现太慢了
git filter-branch -f --prune-empty --index-filter 'git rm -rf --cached --ignore-unmatch shared/log/cron.log' --tag-name-filter cat -- --all
# 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.
命令提示使用 git filter-repo
git filter-repo 去做
使用pip安装:
pip3 install git-filter-repo
或者使用Makefile安装:
make prefix=/usr pythondir=/usr/lib64/python3.8/site-packages install
git filter-repo --invert-paths --path "shared/log/cron.log"
git gc --prune=now