Getting commit sizes in Git?

Is there a way to find out how much space was used by each commit? If I push after each commit, I will see how much data is sent. This is one way of estimating it. But there must be a better way.

Accepted solution gives me following output:

$ ./git-commit-sizes 
1494 40eb8832156be81711f3816f04031cf3b8ef16b0 2
0 fbfb9f4c1f7ae403b9d8b4e194e384c6c41283ad 2
1961638 35e59833bad00edff2c5e8600eb4e62251606556 23
0 49cffee125318113d5dbe6f81e4ce12dcc07263d 2

Each line represents one commit, giving three information:

bytes used, sha1 name, files changed


Solution 1:

Here is a perl script to determine the size of each Git commit:

The source is here, I have added one modification:

#!/usr/bin/perl
foreach my $rev (`git rev-list --all --pretty=oneline`) {
  my $tot = 0;
  ($sha = $rev) =~ s/\s.*$//;
  foreach my $blob (`git diff-tree -r -c -M -C --no-commit-id $sha`) {
    $blob = (split /\s/, $blob)[3];
    next if $blob == "0000000000000000000000000000000000000000"; # Deleted
    my $size = `echo $blob | git cat-file --batch-check`;
    $size = (split /\s/, $size)[2];
    $tot += int($size);
  }
  my $revn = substr($rev, 0, 40);
#  if ($tot > 1000000) {
    print "$tot $revn " . `git show --pretty="format:" --name-only $revn | wc -l`  ;
#  }
}

Start the script in your git repository.

<path_to_script>/commit-size | awk '/\s80973c0/ {print $1 " bytes"}'  80973c0

My example:

± commit-size | awk '/\se920f35/ {print $1 " bytes"}'  
546 bytes