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 o
I've tried with:
git log | grep Date | awk '{print " : "$4" "$3" "$6}' | uniq -c
And it works. You'll get something like:
5 : 3 Mar 2016
4 : 2 Mar 2016
8 : 1 Mar 2016
[...]
I found the command here.
This answers the "per day" side of the identity-crisis question you 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 a
uthor d
ate in our preferred date-format
. If you wanted, you could instead use cd
for c
ommit d
ate, 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}'
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