[英]How to fetch no of commits made by developer for a day in Git repository for a particular branch
Im trying to send a report which contains Count of commits done by developers everyday in git repository. 我试图发送一个报告,其中包含开发人员每天在git存储库中完成的提交计数。
#read all the inputs
read -p "Enter the Branch Name:" branchname
read -p "Enter the from date:" frmdate
read -p "Enter the To date:" todate
#execute the command to get the commit history
git log origin/$branchname --name-status --pretty=format:"%cn committed %h on %cd full" --after="$frmdate 00:00" --before="$todate 23:59" --decorate | git shortlog -s -n > history.txt
This script help me to create a file which contains what are the files changed and by whom on a given date. 这个脚本帮助我创建一个文件,其中包含在给定日期更改的文件和由谁更改的文件。 But i need the count of commits made by indvidual devlopers.
但我需要由独立开发者提交的提交数量。
I tried with git shortlog -s -n
, It gives the overall commit count by developer in all branches. 我尝试使用
git shortlog -s -n
,它提供了所有分支中开发人员的总体提交计数。
Need to create a report to get the commit count of each developer in a daily basis 需要创建报告以每天获取每个开发人员的提交计数
Well.... what I would do is: 好吧......我会做的是:
It would be something like: 它会是这样的:
the_date=$( date +%F )
git log --pretty="%ae" --since=yesterday the-branch | sort | uniq | while read author; do
git log --author=$author --since-yesterday the-branch > "$the_date"_"$author".txt
done
If you need more information (like the files that were changed and so on, just add more options to the log call inside the while cycle. 如果您需要更多信息(例如已更改的文件等,只需在while循环内的日志调用中添加更多选项。
Try this in one line (as one command): 在一行中尝试这个(作为一个命令):
git log --pretty="%cd %aE" --date='format:%Y-%m-%d' BRANCH |
sort -r |
uniq -c |
grep AUTHOR_YOU_ARE_INTERESTED_IN
Example output: 示例输出:
1 2017-05-10 sylvie@bit-booster.com
2 2017-04-13 sylvie@bit-booster.com
1 2017-03-30 sylvie@bit-booster.com
1 2017-03-03 sylvie@bit-booster.com
2 2017-01-24 sylvie@bit-booster.com
1 2016-12-14 sylvie@bit-booster.com
1 2016-11-23 sylvie@bit-booster.com
1 2016-11-21 sylvie@bit-booster.com
1 2016-11-18 sylvie@bit-booster.com
3 2016-11-16 sylvie@bit-booster.com
Missing dates in the report imply no commits for that person on that branch on the missing dates. 报告中缺少日期意味着在失踪日期对该分支机构的任何人没有提交。
The number on the far left (1, 2, 1, 1, etc...) is the # of commits that author had committed on that day. 最左边的数字(1,2,1,1等等)是作者当天提交的提交数。
I think the code block below should work for you. 我认为下面的代码块应该适合你。
#read all the inputs
read -p "Enter the Branch Name:" branchname
read -p "Enter the from date:" frmdate
read -p "Enter the To date:" todate
#execute the command to get the commit history
git log origin/$branchname --pretty=format:"%cn %ci" \
--after="$frmdate 00:00" --before="$todate 23:59"|
gawk '{arr[$2][$1]++}
END{
PROCINFO["sorted_in"] = "@ind_str_desc";
for (date_arr in arr){
printf("%s:\n", date_arr);
PROCINFO["sorted_in"] = "@val_num_desc";
for (author in arr[date_arr]){
printf("\t%s: %s\n", author, arr[date_arr][author]);
}
}
}'
echo "=================================="
git shortlog -s -n
The logic is: 逻辑是:
group by
and order by
query with help of gawk. group by
并按查询order by
。 *Notice that this doesnot work for author name with whitespace in it. *请注意,这对于带有空格的作者姓名不起作用。
git shortlog
can produce a report of commit counts per developer within a range of commits. git shortlog
可以在一系列提交中生成每个开发人员的提交计数报告。 Given start and end dates, you could find the SHA1 to use as range endpoints using git rev-list
, for example: 给定开始日期和结束日期,您可以使用
git rev-list
找到要用作范围端点的SHA1,例如:
start=$(git rev-list -n1 master --before START_DATE)
end=$(git rev-list -n1 master --before END_DATE)
git shortlog -sn $start..$end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.