Skip to content

A simple script to show the size of the commits in Mb, useful to identify large commits that size up a git repository.

Notifications You must be signed in to change notification settings

vlab22/git-commit-size

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

git-commit-size

A simple script to show the commits' size in Mb, useful to identify large commits that size up a git repository.

Based on the example on: https://confluence.atlassian.com/fishkb/determine-the-size-of-each-git-commit-292651328.html

The code with minor modifications:

#!/usr/bin/perl
foreach my $rev (`git rev-list --all --pretty=oneline`) {
  my $tot = 0;
  ($sha = $rev) =~ s/\s.*$//;
  my ( $rev_desc ) = $rev=~ /( .*)\s*$/;
  $rev_desc =~ s/^\s+|\s+$//g;
  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);
  
  # 1 byte, change to 1000 for example, to show only commits greater than 1Mb
  if ($tot > 1) {
	$mb_tot = $tot / 1024 / 1024;
	$mb_tot_str = sprintf('%.2f', $mb_tot);
    print "$mb_tot_str Mb $rev_desc $revn " . `git show --pretty="format:" --name-only $revn | wc -l`  ;
  }
}

Put this file in the "PATH", in Windows, a good folder could be the Git\cmd folder (C:\Program Files\Git\cmd\), if it is in the PATH

Run from the Git Bash command prompt in a repository folder.

About

A simple script to show the size of the commits in Mb, useful to identify large commits that size up a git repository.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages