我如何“滥用”责备(或一些更合适的函数,和/或与shell命令结合)来给我一个关于当前存储库中有多少行(代码)来自每个提交者的统计数据?
示例输出:
Committer 1: 8046 Lines
Committer 2: 4378 Lines
我如何“滥用”责备(或一些更合适的函数,和/或与shell命令结合)来给我一个关于当前存储库中有多少行(代码)来自每个提交者的统计数据?
示例输出:
Committer 1: 8046 Lines
Committer 2: 4378 Lines
当前回答
请从http://gitstats.sourceforge.net/查看gitstats命令
其他回答
这适用于repo源结构的任何目录,以防您想检查某个源模块。
find . -name '*.c' | xargs -n1 git blame --line-porcelain | grep "^author "|sort|uniq -c|sort -nr
我采用了Powershell最上面的答案:
(git ls-tree -rz --name-only HEAD).Split(0x00) | where {$_ -Match '.*\.py'} |%{git blame -w --line-porcelain HEAD $_} | Select-String -Pattern '^author ' | Group-Object | Select-Object -Property Count, Name | Sort-Object -Property Count -Descending
是否使用-w开关运行git blame是可选的,我添加它是因为它会忽略空白的更改。
虽然Bash解决方案在WSL2下运行,但我的机器上的性能对Powershell有利(在相同的repo下~50秒vs ~65秒)
Bash函数,目标是在MacOS上运行的单个源文件。
function glac {
# git_line_author_counts
git blame -w "$1" | sed -E "s/.*\((.*) +[0-9]{4}-[0-9]{2}.*/\1/g" | sort | uniq -c | sort -nr
}
我有这个解决方案,计数在所有文本文件(不包括二进制文件,甚至版本化的):
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
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完好无损。