Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Calculate size of a git commit object.
if [ $# -ne 1 ]; then
echo "Usage: <commit hash>" 1>&2
exit 1
ITEM_LIST="`git diff-tree -r -c -M -C --no-commit-id $HASH`"
BLOB_HASH_LIST="`echo "$ITEM_LIST" | awk '{ print $4 }'`"
SIZE_LIST="`echo "$BLOB_HASH_LIST" | git cat-file --batch-check | grep "blob" | awk '{ print $3}'`"
COMMIT_SIZE="`echo "$SIZE_LIST" | awk '{ sum += $1 } END { print sum }'`"

This comment has been minimized.

Copy link

ric2b commented Jan 31, 2020

This is really nice but could you clarify in what unit this is measuring? "$COMMIT_SIZE bytes"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.