我有一个目录,其中有很多 Git repo 子目录,我想积累类似的信息
git shortlog -sne --no-merges
对于其中的所有存储库,按所有总提交对用户进行排序。
例如,对于存储库 1:
430 Author 1 <[email protected] /cdn-cgi/l/email-protection>
20 Author 2 <[email protected] /cdn-cgi/l/email-protection>
例如,对于存储库 2:
123 Author 1 <[email protected] /cdn-cgi/l/email-protection>
92 Author 2 <[email protected] /cdn-cgi/l/email-protection>
总结果:
453 Author 1 <[email protected] /cdn-cgi/l/email-protection>
112 Author 2 <[email protected] /cdn-cgi/l/email-protection>
是否可以使用 git 内置工具来做到这一点?
我能够走出存储库文件夹并为单个文件夹运行它:
git -C repoFolder shortlog -sne --no-merges
cd
循环进入每个子目录和进程git shortlog
输出与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}'
The awk
脚本解释:
name_email="";
对于每个输入行:以空变量开头name_email
.
for (i=2; i<=NF; i++) {name_email=name_email " " $i};
将从 2 开始的所有字段(以空格分隔)连接起来name_email
。 IE。合并所有姓名+电子邮件字段。
count_by_user[name_email]+=$1
创建一个新的关联数组count_by_user
并在每一行中增加第一个字段的值(默认为 0)(提交计数)。
END {for (name_email in count_by_user) print count_by_user[name_email], name_email}
最后打印结果:run throughcount_by_user
索引(姓名+电子邮件),打印计算的计数器,打印姓名+电子邮件。结果打印时未排序。可以排序在非常awk
脚本或后处理| sort -nr
.
开发与gawk
的版本awk
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)