Git提交计数一天
我有一个名为 development
的分支。现在,我想知道每天(即每天)发生多少次提交。
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
这将回答您所提出的身份危机问题的每天问题,这似乎无法决定是否要每天表示多个,或者一天表示单个。显然,每天是一天的超集,因此这对展示很有用; grep
这样就可以完成其余工作。
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.
又甜又甜:
git log --date=short --pretty=format:%ad | sort | uniq -c
示例输出:
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
说明:
-
git log
显然是先决条件。 / li>
-
-date = short
将日期格式
设置为YYYY-MM-DD
,这(A)是我们所需要的,而(B)随后将按字母顺序将排序
按时间顺序排列。 -
-pretty = format:%ad
告诉git
以我们首选的date格式$ c获取每个提交的
a
uthord
ate $ c>。如果需要,您可以使用cd
代替c
mmitd
ate,但是一旦您樱桃采摘
,变基
等,它就会变得有用得多。 -
|。
,因为它仅检查相邻的重复项。当然,我们几乎肯定希望无论如何都要在最后对日期进行排序。uniq
需要sort -
| uniq -c
计算每个YYYY-MM-DD
的相邻重复项的数量,并将其加到日期之前。
-
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.
喜剧奖金:如果您希望将其作为制表符分隔的日期,则应进行计数,以输入到图形引擎中或类似的方法,然后将上述结果传递到
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'
就是这么简单...!
或者,避免发疯,只需使用 awk
而不是 sed
:
Alternatively, avoid going mad by just using awk
instead of sed
:
awk 'BEGIN{OFS = "\t"} {print $2, $1}'