最近有个开源项目要推送到社区,但发现仓库提示太大了,有几百MB,实际通过下载的话,发现也就10MB上下,分支的话也就2个,因此怀疑是Git Log导致的仓库过大问题。
安装
brew install git-filter-repo
排查哪些路径文件
git rev-list --objects --all \
| git cat-file --batch-check='%(objectname) %(objecttype) %(objectsize) %(rest)' \
| grep ' blob ' \
| sort -k3 -nr \
| head -20 \
| awk '{
size=$3;
path=$4;
for (i=5; i<=NF; i++) path=path " " $i;
if (size >= 1024*1024*1024)
printf "%.2f GB\t%s\n", size/1024/1024/1024, path;
else
printf "%.2f MB\t%s\n", size/1024/1024, path;
}'

解决方案
- git filter-repo –path xxx –invert-paths –force
- git push –force
结论
- repo 大 ≠ 当前文件大
- 历史里有大文件(即使你已经删了)