Git如何清理大文件?

当本地删除了大文件还是存在git里提交不了到仓库?
1.首先找到占用最大的文件

git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| awk '/^blob/ {print substr($0,6)}' \
| sort --numeric-sort --key=2 \
| cut --complement --characters=13-40 \
| numfmt --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest

2.找到占用最大的文件名过后 (下面假设我有2个大文件,名字为a 和 b)

git filter-branch --index-filter 'git rm --cached --ignore-unmatch a b' HEAD

3.释放大文件内存


rm -rf .git/refs/original/

git reflog expire --expire=now --all

git fsck --full --unreachable

git repack -A -d

git gc --aggressive --prune=now

然后你就可以按照正常流程提交到仓库了

posted @ 2022-12-08 00:06  anhiao  阅读(431)  评论(0编辑  收藏  举报