Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch no of commits made by developer for a day in Git repository for a particular branch

Tags:

git

shell

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

like image 916
user2439278 Avatar asked Apr 25 '17 11:04

user2439278


People also ask

How do you find the number of commits per author?

To get the number of commits for each user execute git shortlog -sn --all. To get the number of lines added and delete by a specific user install q and then execute: git log --author="authorsname" --format=tformat: --numstat | q -t "select sum(c1), sum(c2) from -"

How do you view commits made in a branch?

On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.

Which command is used to check last 5 commits by a particular author?

The git shortlog command is a special version of git log intended for creating release announcements. It groups each commit by author and displays the first line of each commit message.


2 Answers

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.

like image 167
eftshift0 Avatar answered Sep 28 '22 15:09

eftshift0


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.

like image 33
G. Sylvie Davies Avatar answered Sep 28 '22 14:09

G. Sylvie Davies