我如何“滥用”责备(或一些更合适的函数,和/或与shell命令结合)来给我一个关于当前存储库中有多少行(代码)来自每个提交者的统计数据?
示例输出:
Committer 1: 8046 Lines
Committer 2: 4378 Lines
我如何“滥用”责备(或一些更合适的函数,和/或与shell命令结合)来给我一个关于当前存储库中有多少行(代码)来自每个提交者的统计数据?
示例输出:
Committer 1: 8046 Lines
Committer 2: 4378 Lines
当前回答
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
其他回答
git shortlog -sec
这将显示每个作者的提交列表。
我写了一个叫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 |
+----------------+-----+---------+-------+---------------------+
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
}
我采用了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秒)
我有这个解决方案,计数在所有文本文件(不包括二进制文件,甚至版本化的):
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