我如何“滥用”责备(或一些更合适的函数,和/或与shell命令结合)来给我一个关于当前存储库中有多少行(代码)来自每个提交者的统计数据?

示例输出:

Committer 1: 8046 Lines
Committer 2: 4378 Lines

当前回答

Erik的解决方案非常棒,但我在变音符上遇到了一些问题(尽管我的LC_*环境变量表面上设置正确),并且在实际上包含日期的代码行中泄漏了噪音。我的sed-fu很差,所以我最终得到了这个带有红宝石的弗兰肯斯坦代码片段,但它在20万+ LOC上完美无缺地为我工作,并对结果进行了分类:

git ls-tree -r HEAD | gsed -re 's/^.{53}//' | \
while read filename; do file "$filename"; done | \
grep -E ': .*text' | gsed -r -e 's/: .*//' | \
while read filename; do git blame "$filename"; done | \
ruby -ne 'puts $1.strip if $_ =~ /^\w{8} \((.*?)\s*\d{4}-\d{2}-\d{2}/' | \
sort | uniq -c | sort -rg

还要注意gsed而不是sed,因为这是二进制的自制程序安装,使系统sed完好无损。

其他回答

我有这个解决方案,计数在所有文本文件(不包括二进制文件,甚至版本化的):

IFS=$'\n'
for file in $(git ls-files); do
    git blame `git symbolic-ref --short HEAD` --line-porcelain "$file" | \
        grep  "^author " | \
        grep -v "Binary file (standard input) matches" | \
        grep -v "Not Committed Yet" | \
        cut -d " " -f 2-
    done | \
        sort | \
        uniq -c | \
        sort -nr

我写了一个叫git-fame的gem,可能有用。

安装使用:

$ gem安装git_fame $ CD /path/to/gitdir $ git名声

输出:

Statistics based on master
Active files: 21
Active lines: 967
Total commits: 109

Note: Files matching MIME type image, binary has been ignored

+----------------+-----+---------+-------+---------------------+
| name           | loc | commits | files | distribution (%)    |
+----------------+-----+---------+-------+---------------------+
| Linus Oleander | 914 | 106     | 21    | 94.5 / 97.2 / 100.0 |
| f1yegor        | 47  | 2       | 7     |  4.9 /  1.8 / 33.3  |
| David Selassie | 6   | 1       | 2     |  0.6 /  0.9 /  9.5  |
+----------------+-----+---------+-------+---------------------+

git shortlog -sec

这将显示每个作者的提交列表。

请从http://gitstats.sourceforge.net/查看gitstats命令

Erik的解决方案非常棒,但我在变音符上遇到了一些问题(尽管我的LC_*环境变量表面上设置正确),并且在实际上包含日期的代码行中泄漏了噪音。我的sed-fu很差,所以我最终得到了这个带有红宝石的弗兰肯斯坦代码片段,但它在20万+ LOC上完美无缺地为我工作,并对结果进行了分类:

git ls-tree -r HEAD | gsed -re 's/^.{53}//' | \
while read filename; do file "$filename"; done | \
grep -E ': .*text' | gsed -r -e 's/: .*//' | \
while read filename; do git blame "$filename"; done | \
ruby -ne 'puts $1.strip if $_ =~ /^\w{8} \((.*?)\s*\d{4}-\d{2}-\d{2}/' | \
sort | uniq -c | sort -rg

还要注意gsed而不是sed,因为这是二进制的自制程序安装,使系统sed完好无损。