9

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

1
10

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
4
  • @ArekBulski You're right. – A.B. May 5 '15 at 6:28
  • Good question, good answer... ;-) – Fabby Aug 23 '15 at 13:23
  • @A.B., How can you run a perl script without the perl command? – Iulian Onofrei Jul 18 '16 at 14:19
  • 1
    @IulianOnofrei you need perl installed at the very least. But the first line #!/usr/bin/perl tells the shell what interpreter to use. So if you set the script to executable (chmod +x path/to/script), a shell is happy to run that. – kjprice Sep 19 '16 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.