如何使用git shortlog汇总单个目录中多个存储库上的用户提交统计信息? [英] How to use git shortlog to aggregate user commit stats over multiple repositories in a single directory?
问题描述
我的目录中包含很多Git存储库子目录,我想积累类似于
I have a directory with a lot of Git repo subdirectories in it and I would like to accumulate information similar to
git shortlog -sne --no-merges
其中的所有存储库按用户的总提交次数对其进行排序.
for all the repos in it sorting the users by all their total commits.
例如回购1:
430 Author 1 <author1@email.com>
20 Author 2 <author2@email.com>
例如回购2:
123 Author 1 <author1@email.com>
92 Author 2 <author2@email.com>
总结果:
453 Author 1 <author1@email.com>
112 Author 2 <author2@email.com>
是否可以使用git内置工具来做到这一点?
Is it possible to do that with git built-in tools?
我能够走出repo文件夹,并为单个文件夹运行它:
I was able to go outside of the repo folders and run that for a single folder:
git -C repoFolder shortlog -sne --no-merges
推荐答案
cd
循环进入每个子目录,并使用 awk 日志记录处理日志
代码>:
cd
in a loop into every subdirectory and process git shortlog
output with awk
:
for d in *; do git -C $d shortlog -ens --no-merges; done |
awk '{name_email=""; for (i=2; i<=NF; i++) {name_email=name_email " " $i}; count_by_user[name_email]+=$1} END {for (name_email in count_by_user) print count_by_user[name_email], name_email}'
awk
脚本说明:
name_email="";
对于每个输入行:以空变量 name_email
开头.
For every input line: start with empty variable name_email
.
for (i=2; i<=NF; i++) {name_email=name_email " " $i};
将以2个空格开头的所有字段分隔为 name_email
.IE.合并所有名称和电子邮件字段.
Join all fields starting from 2 space-separated into name_email
. I.e. combine all name+email fields.
count_by_user[name_email]+=$1
创建一个新的关联数组 count_by_user
,并在每行中将值(默认值为0)增加到第一个字段的值(提交计数).
Create a new associative array count_by_user
and in every line increase value (default is 0) by the value of the first field (commits count).
END {for (name_email in count_by_user) print count_by_user[name_email], name_email}
最后打印结果:运行 count_by_user
索引(名称+电子邮件),打印计算出的计数器,打印名称+电子邮件.结果未排序打印.可以在非常 awk
脚本中排序,也可以使用 |后处理排序-nr
.
At the end print results: run through count_by_user
indices (name+email), print the calculated counter, print name+email. Results are printed unsorted. Could be sorted in the very awk
script or post-processed with | sort -nr
.
使用 awk
的 gawk
版本开发.
这篇关于如何使用git shortlog汇总单个目录中多个存储库上的用户提交统计信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!