Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Calculate size of a git commit object.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: git-commit-size.sh <commit hash>" 1>&2
exit 1
fi
HASH=$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 }'`"
echo "$COMMIT_SIZE"
@ric2b

This comment has been minimized.

Copy link

@ric2b ric2b commented Jan 31, 2020

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

@stuntguy3000

This comment has been minimized.

Copy link

@stuntguy3000 stuntguy3000 commented Nov 28, 2020

I do believe it is Bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment