在 Git 中获取提交大小?

Are*_*ski 9 command-line git

有没有办法找出每次提交使用了多少空间?如果我在每次提交后推送,我会看到发送了多少数据。这是估计它的一种方法。但必须有更好的方法。

接受的解决方案给了我以下输出:

$ ./git-commit-sizes 
1494 40eb8832156be81711f3816f04031cf3b8ef16b0 2
0 fbfb9f4c1f7ae403b9d8b4e194e384c6c41283ad 2
1961638 35e59833bad00edff2c5e8600eb4e62251606556 23
0 49cffee125318113d5dbe6f81e4ce12dcc07263d 2
Run Code Online (Sandbox Code Playgroud)

每行代表一次提交,提供三个信息:

使用的字节数、sha1 名称、文件已更改

A.B*_*.B. 10

这是一个 perl 脚本,用于确定每个 Git 提交的大小:

来源在这里,我添加了一个修改:

#!/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`  ;
#  }
}
Run Code Online (Sandbox Code Playgroud)

在您的 git 存储库中启动脚本。

<path_to_script>/commit-size | awk '/\s80973c0/ {print $1 " bytes"}'  80973c0
Run Code Online (Sandbox Code Playgroud)

我的例子:

± commit-size | awk '/\se920f35/ {print $1 " bytes"}'  
546 bytes
Run Code Online (Sandbox Code Playgroud)