Im trying to send a report which contains Count of commits done by developers everyday in git repository.
#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.
Need to create a report to get the commit count of each developer in a daily basis
4 Answers
Answers 1
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.
Answers 2
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.
Answers 3
git shortlog
can produce a report of commit counts per developer within a range of commits. Given start and end dates, you could find the SHA1 to use as range endpoints using git rev-list
, for example:
start=$(git rev-list -n1 master --before START_DATE) end=$(git rev-list -n1 master --before END_DATE) git shortlog -sn $start..$end
Answers 4
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:
- Get commits rows with 2 columns: commit author and commit date;
- Make a SQL-like
group by
andorder by
query with help of gawk.
*Notice that this doesnot work for author name with whitespace in it.
0 comments:
Post a Comment