问题
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
回答1:
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 ourdate-format
toYYYY-MM-DD
, which (A) is all we need and (B) will subsequently alphabeticallysort
into chronological order.--pretty=format:%ad
tellsgit
that we only want to get each commit'sa
uthord
ate in our preferreddate-format
. If you wanted, you could instead usecd
forc
ommitd
ate, but that tends to get a lot less useful as soon as youcherry-pick
,rebase
, etc.| sort
is needed foruniq
, 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 eachYYYY-MM-DD
and prepends that count to the date.
回答2:
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
回答3:
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.
来源:https://stackoverflow.com/questions/35769003/git-commit-count-a-day