user2439278
user2439278

Reputation: 1214

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.

#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

Upvotes: 5

Views: 1271

Answers (4)

YwH
YwH

Reputation: 1140

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. Make a SQL-like group by and order by query with help of gawk.

*Notice that this doesnot work for author name with whitespace in it.

Upvotes: 1

janos
janos

Reputation: 124646

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

Upvotes: 1

G. Sylvie Davies
G. Sylvie Davies

Reputation: 5517

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 [email protected]
  2 2017-04-13 [email protected]
  1 2017-03-30 [email protected]
  1 2017-03-03 [email protected]
  2 2017-01-24 [email protected]
  1 2016-12-14 [email protected]
  1 2016-11-23 [email protected]
  1 2016-11-21 [email protected]
  1 2016-11-18 [email protected]
  3 2016-11-16 [email protected]

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.

Upvotes: 3

eftshift0
eftshift0

Reputation: 30166

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.

Upvotes: 3

Related Questions