Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit count a day

Tags:

git

commit

I have a branch called development. Now I want to know how many commits are happened per day (i.e) each day.

I want Toal number of commits (i.e) count of commits in a day.

I tried this command, but it is giving all commits count from the branch

git shortlog -s -n

My question is count number of commits in a day

like image 647
Sanjay Dutt Avatar asked Mar 03 '16 10:03

Sanjay Dutt


People also ask

Does git show time of commit?

In the commit logs, Git displays the timestamp in the format localtime + timezone offset. When reading the timestamps it's important to take the timezone offset into account. Using the timezone offset you can convert the timestamp of the Commit 2 and Commit 3 into the UTC time in order to compare them.

How do I find commit history?

`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.


2 Answers

This answers the "per day" side of the question asked, which can't seem to decide whether it wants "per/each day" implying multiple or just "a day" implying single. ;-) Obviously, "per day" is a superset of "a day", so that's the one that's useful to show; grep and such can do the rest!

Short and sweet:

git log --date=short --pretty=format:%ad | sort | uniq -c

Example output:

      1 2017-12-08
      6 2017-12-26
     12 2018-01-01
     13 2018-01-02
     10 2018-01-14
      7 2018-01-17
      5 2018-01-18

Explanation:

  • git log is a prerequisite, obviously.
  • --date=short sets our date-format to YYYY-MM-DD, which (A) is all we need and (B) will subsequently alphabetically sort into chronological order.
  • --pretty=format:%ad tells git that we only want to get each commit's author date in our preferred date-format. If you wanted, you could instead use cd for commit date, but that tends to get a lot less useful as soon as you cherry-pick, rebase, etc.
  • | sort is needed for uniq, as it only checks for adjacent duplicates. And of course, we almost certainly want the dates to be ordered at the end anyway.
  • | uniq -c counts the number of adjacent duplicates for each YYYY-MM-DD and prepends that count to the date.

comedy bonus: if you want that as a tab-separated date then count, for input into a graphing engine or suchlike, then just pipe the above result into

sed 's:^  *\([1-9][0-9]*\) \([1-9][0-9-]*\)$:\2\t\1:g'

It's that simple...!

Alternatively, avoid going mad by just using awk instead of sed:

awk 'BEGIN{OFS = "\t"} {print $2, $1}'
like image 161
underscore_d Avatar answered Oct 07 '22 14:10

underscore_d


Try this:

$ git rev-list --count --since=<start-date> --before=<end-date> <ref>

For example, to get the number of commits done yesterday in the current branch:

$ git rev-list --count --since=yesterday --before=today HEAD

Absolute dates are also accepted:

$ git rev-list --count --since=2016-03-02 --before=2016-03-03 HEAD
like image 33
alextercete Avatar answered Oct 07 '22 14:10

alextercete