Skip to content

Instantly share code, notes, and snippets.

@kobake
Created November 5, 2017 13:42
Show Gist options
  • Save kobake/ef0a18a5b9dfc639819e19c3b0f49e05 to your computer and use it in GitHub Desktop.
Save kobake/ef0a18a5b9dfc639819e19c3b0f49e05 to your computer and use it in GitHub Desktop.
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
Copy link

ric2b commented Jan 31, 2020

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

@stuntguy3000
Copy link

I do believe it is Bytes.

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