Created
November 5, 2017 13:42
-
-
Save kobake/ef0a18a5b9dfc639819e19c3b0f49e05 to your computer and use it in GitHub Desktop.
Calculate size of a git commit object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is really nice but could you clarify in what unit this is measuring?
"$COMMIT_SIZE bytes"
?