How to find the N largest files in a git repository?

后端 未结 9 1685
青春惊慌失措
青春惊慌失措 2020-12-12 14:33

I wanted to find the 10 largest files in my repository. The script I came up with is as follows:

REP_HOME_DIR=
max_huge_files=         


        
9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 14:53

    An improvement to raphinesse's answer, sort by size with largest first:

    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 --reverse \
    | head \
    | cut --complement --characters=13-40 \
    | numfmt --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
    

提交回复
热议问题