Skip to content

Instantly share code, notes, and snippets.

@jitran
Last active February 27, 2024 05:51
Show Gist options
  • Save jitran/2680dd53a61a8cb94d545d78050161ba to your computer and use it in GitHub Desktop.
Save jitran/2680dd53a61a8cb94d545d78050161ba to your computer and use it in GitHub Desktop.
Calculates the size of each commit in the current branch
#!/usr/bin/env bash -e
for commit in $(git log --format="%H"); do
size=0
blobs=0
IFS=$'\n'
for line in $(git log -1 --raw --no-merges --no-renames --no-abbrev --full-index --raw --pretty=oneline $commit | tail -n +2); do
id=$(echo $line | cut -d' ' -f4)
blob_size=$(git cat-file -s $id 2>/dev/null || echo 0)
(( size += blob_size ))
(( blobs += 1 ))
done
echo $commit $blobs $size
done
@jitran
Copy link
Author

jitran commented Feb 27, 2024

The output format is:

<commit-sha> <blob count> <commit size>

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