简体   繁体   English

如何在Git存储库中为特定分支获取开发人员提交的一天提交

[英]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: 好吧......我会做的是:

  • Get the list of developers who worked on the branch since yesterday. 获取自昨天以来在该分支机构工作的开发人员列表。
  • Pipe that list into a while so that you can get what each one did 管道列表一段时间,以便您可以得到每个人做的

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: 逻辑是:

  1. Get commits rows with 2 columns: commit author and commit date; 获取具有2列的提交行:提交作者和提交日期;
  2. Make a SQL-like group by and order by query with help of gawk. 在gawk的帮助下,创建一个类似SQL的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.

相关问题 Git 存储库 - 如何在运行 git filter-branch 后重播对旧存储库所做的更新提交到修改后的存储库 - Git repository - how to replay newer commits made to old repository, to modified repository after running git filter-branch Git工作流:如何合并仅在新分支上进行的提交 - Git workflow: How to merge commits made only on new branch 在切换分支上丢失对 git 的提交 - Lost commits made to git on switching branch Git - 对错误的分支进行正确的提交 - Git - correct commits made to wrong branch 获取 git 中分支的提交次数 - Getting number of commits made to branch in git 如何在特定提交日期之前删除 git 存储库的所有提交? - How to delete all the commits of a git repository before a particular commit date? 是否有可能只在git中看到特定分支中的提交? - Is it possible to see only the commits in a particular branch in git? 通过git commit遍历特定分支的Ruby - Iterate with Ruby through git commits for a particular branch 我怎么知道哪些补丁不包含与上游git存储库在同一分支中提交的git存储库? - How may I know what patches are exclusive of a git repository that commits in the same branch as the upstream git repository? 查看与特定 git 分支有关的提交(和差异) - View commits (and diff) pertaining to a particular git branch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM