我如何“滥用”责备(或一些更合适的函数,和/或与shell命令结合)来给我一个关于当前存储库中有多少行(代码)来自每个提交者的统计数据?
示例输出:
Committer 1: 8046 Lines
Committer 2: 4378 Lines
我如何“滥用”责备(或一些更合适的函数,和/或与shell命令结合)来给我一个关于当前存储库中有多少行(代码)来自每个提交者的统计数据?
示例输出:
Committer 1: 8046 Lines
Committer 2: 4378 Lines
当前回答
请从http://gitstats.sourceforge.net/查看gitstats命令
其他回答
我写了一个叫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 |
+----------------+-----+---------+-------+---------------------+
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完好无损。
git ls-tree -r HEAD|sed -re 's/^.{53}//'|while read filename; do file "$filename"; done|grep -E ': .*text'|sed -r -e 's/: .*//'|while read filename; do git blame -w "$filename"; done|sed -r -e 's/.*\((.*)[0-9]{4}-[0-9]{2}-[0-9]{2} .*/\1/' -e 's/ +$//'|sort|uniq -c
逐级讲解:
列出版本控制下的所有文件
git ls-tree -r HEAD|sed -re 's/^.{53}//'
将列表修剪为仅文本文件
|while read filename; do file "$filename"; done|grep -E ': .*text'|sed -r -e 's/: .*//'
Git责备所有的文本文件,忽略空白的变化
|while read filename; do git blame -w "$filename"; done
找出作者的名字
|sed -r -e 's/.*\((.*)[0-9]{4}-[0-9]{2}-[0-9]{2} .*/\1/' -e 's/ +$//'
排序作者列表,并让uniq计算连续重复的行数
|sort|uniq -c
示例输出:
1334 Maneater
1924 Another guy
37195 Brian Ruby
1482 Anna Lambda
请从http://gitstats.sourceforge.net/查看gitstats命令
我自己的脚本是@nilbus和@Alex的组合
#!/bin/sh
for f in $(git ls-tree -r --name-only HEAD --);
do
j=$(file "$f" | grep -E ': .*text'| sed -r -e 's/: .*//');
if [ "$f" != "$j" ]; then
continue;
fi
git blame -w --line-porcelain HEAD "$f" | grep "^author " | sed 's/author //'`enter code here`
done | sort | uniq -c | sort -nr