是否有可能获得有关每次提交更改浪费了多少空间的信息 - 因此我可以找到提交大文件或大量文件的提交。这是所有尝试减少git repo大小(重新绑定和可能筛选提交)git find fat commit
回答
忘了回答,我的回答是:
git rev-list --all --pretty=format:'%H%n%an%n%s' # get all commits
git diff-tree -r -c -M -C --no-commit-id #{sha} # get new blobs for each commit
git cat-file --batch-check << blob ids # get size of each blob
@sschuberth:如果我正确地读你的脚本,它只考虑在特定提交中被添加_的文件。它不会检测到文件在提交时大幅增长。 – kynan 2012-04-19 00:07:58
@ kynan:你说得对,因为这是OP要求的(以及我需要的)。但是很容易改变脚本来检测修改过的文件:基本上你只需要在grep调用中用“M”代替“A”。这将报告修改后的总文件大小(而不是添加/删除的字节数)。我很乐意接受GitHub上的pull请求,以使脚本更通用。 – sschuberth 2012-04-24 14:04:12
断开的链接,脚本现在位于[这里](https://github.com/sschuberth/dev-scripts/blob/master/git/git-commit-size.sh) – Luke 2012-12-15 01:55:18
git cat-file -s <object>
其中<object>
可以引用提交,blob,树或标记。如果你需要看不同的分支,你”
git ls-tree -r -t -l --full-name HEAD | sort -n -k 4
这将显示在底部的最大文件(第四列是文件(BLOB)大小
:
你能做到这一点。 。会想改变HEAD那些分支名称或者,把这种在一个循环中满枝头,标签,或加快转速您有兴趣
就个人而言,我发现这个答案试图找到一个git回购的历史大文件时最有帮助:Find files in git repo over x megabytes, that don't exist in HEAD
#!/bin/bash
COMMITSHA=$1
CURRENTSIZE=$(git ls-tree -lrt $COMMITSHA | grep blob | sed -E "s/.{53} *([0-9]*).*/\1/g" | paste -sd+ - | bc)
PREVSIZE=$(git ls-tree -lrt $COMMITSHA^ | grep blob | sed -E "s/.{53} *([0-9]*).*/\1/g" | paste -sd+ - | bc)
echo "$CURRENTSIZE - $PREVSIZE" | bc
而且我建议使用git format-patch来获取提交大小(邮件头将会有一些额外的大小,但实际上如果您需要快速提交并不是太大 - 这并不重要得到确切的大小,+ - 1K将是很好的准确性) – 2014-06-19 16:09:34
git fat find N
其中N是以字节为单位将返回在整个的所有文件历史大于N字节。
你可以找到更多关于git的发在这里:https://github.com/cyaninc/git-fat
无赖。我在GitHub桌面上的Git Shell上试了一下,并且这个命令没有工作,给我一个错误。 – DucRP 2017-01-09 15:06:17
所有在这里提供的解决方案的重点文件大小,但原来的问题问的是关于犯尺寸,这在我看来,和在我的例子中,找到更重要的是(因为我想要的是摆脱单个提交中引入的许多小型二进制文件,总结出的大小很大,但是如果按文件单独测量则小)。
,专注于提交尺寸是提供here一种解决方案,这是该perl脚本:
#!/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` ;
# }
}
和我这样调用:
./git-commit-sizes.pl | sort -n -k 1
- 1. git-svn dmitmiting git commit
- 2. Aptana 3 git commit
- 3. Git post commit mails
- 4. git commit problems
- 5. 删除git commit
- 6. git commit - 格式?
- 7. SLOC在git commit
- 8. Git commit命令
- 9. git commit directory
- 10. Git commit date
- 11. git post-commit钩子
- 12. git commit to github repo
- 13. git fast-forward one commit
- 14. git commit queue工具
- 15. Git commit bash脚本
- 16. git commit sublime text 2
- 17. 撤消git commit --amend
- 18. ^在Git commit消息中的M个字符(git commit -v)
- 19. 有没有'git find'?
- 20. 如何在git推后执行git commit?
- 21. git add→git commit。这是正确的吗?
- 22. 什么做“git checkout \ *”和“git commit - ”完成?
- 23. 删除第一个git commit
- 24. 恢复以前的git commit?
- 25. Git commit count count a day
- 26. 如何中止'git commit --amend'?
- 27. 使用git commit -a和vim
- 28. 为Redmine设置git commit hook
- 29. 如何搜索git commit comments?
- 30. Capistrano得到git commit sha1
请考虑只运行'git的gc'偶尔,可能是'git gc --ggressive' – Hasturkun 2009-08-17 07:33:43
'git gc'(和'git gc --prune'); '--aggresive'甚至可以给出更糟的结果(但通常不应该),通常不值得。 – 2009-08-17 19:55:37
这个答案好多了:http://stackoverflow.com/a/10847242/520567 – akostadinov 2014-06-09 13:32:32