git- 查看代码库的文件大小
2019-07-10 本文已影响3人
精神病患者link常
安装 brew install coreutils
cd 到git目录,执行
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| sort --numeric-sort --key=2 \
| cut -c 1-12,41- \
| $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
![](https://img.haomeiwen.com/i23011/c10365687c99d891.png)
要想显示超过多少大小的文件:比如显示超过1MB的文件
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| sort --numeric-sort --key=2 \
| cut -c 1-12,41- \
| grep -vF --file=<(git ls-tree -r HEAD | awk '{print $3}') \
| awk '$2 > 1048576' \
| $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
![](https://img.haomeiwen.com/i23011/7544285cbf128032.png)
参考地址:https://stackoverflow.com/questions/10622179/how-to-find-identify-large-commits-in-git-history