Skip to content

Instantly share code, notes, and snippets.

@beenotung
Created September 13, 2023 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beenotung/5f8610007d10ffd0515804249a92a89b to your computer and use it in GitHub Desktop.
Save beenotung/5f8610007d10ffd0515804249a92a89b to your computer and use it in GitHub Desktop.
find large files from git blob store
#!/bin/bash
set -e
set -o pipefail
case "$1" in
-s|--sum)
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| awk '{x+=$1}END{print x}' \
| $(command -v gnumfmt || echo numfmt) --field=1 --to=iec-i --suffix=B --round=nearest
exit
;;
-r)
order="-rn"
;;
*)
order="-n"
;;
esac
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| sort "$order" --key=2 \
| cut -c 1-12,41- \
| $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment