我有一个目录,里面有很多 Git repo 子目录,我想积累类似于
git shortlog -sne --no-merges
对于其中的所有 repo 协议(protocol),按用户的所有总提交对用户进行排序。
例如 repo 1:
430 Author 1 <author1@email.com>
20 Author 2 <author2@email.com>
例如 repo 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 内置工具来做到这一点?
我能够走出 repo 文件夹并为单个文件夹运行它:
git -C repoFolder shortlog -sne --no-merges
最佳答案
cd
循环进入每个子目录并使用 awk
处理 git shortlog
输出:
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 (i=2; i<=NF; i++) {name_email=name_email " " $i};
将所有以空格分隔的 2 开始的字段连接到 name_email
中。 IE。 merge 所有姓名+电子邮件字段。
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}
最后打印结果:运行count_by_user
indices (name+email),打印计算出的计数器,打印name+email。结果未分类打印。可以在 awk
脚本中排序或使用 | 进行后处理排序-nr
.
使用 awk
的 gawk
版本开发。
关于bash - 如何使用 git shortlog 聚合单个目录中多个存储库的用户提交统计信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59888730/