gpt4 book ai didi

bash - 如何使用 git shortlog 聚合单个目录中多个存储库的用户提交统计信息?

转载 作者:行者123 更新时间:2023-12-02 09:04:45 25 4
gpt4 key购买 nike

我有一个目录,里面有很多 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.

使用 awkgawk 版本开发。

关于bash - 如何使用 git shortlog 聚合单个目录中多个存储库的用户提交统计信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59888730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com