我有一个分支叫
development
。现在我想知道每天发生了多少次提交。
我尝试了这个命令,但它正在计算分支的所有提交
git shortlog -s -n
简短而甜蜜:
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
是先决条件。--date=short
将我们的 date-format
设置为 YYYY-MM-DD
,其中 (A) 就是我们所需要的,(B) 随后将按字母顺序 sort
按时间顺序排列。--pretty=format:%ad
告诉git
,我们只想获取每个提交的a
作者d
在我们首选的date-format
中。如果你愿意,你可以使用 cd
来 c
提交 d
ate,但是一旦你 cherry-pick
、rebase
等| sort
是 uniq
所必需的,因为它只检查相邻的重复项。当然,我们几乎肯定希望日期在最后排序。| uniq -c
计算每个 YYYY-MM-DD
的相邻重复项的数量,并将计数添加到日期之前。如果您希望将其作为制表符分隔的日期,然后进行计数,以便输入到图形引擎或类似引擎中,则只需将上述结果通过管道传输到
awk 'BEGIN{OFS = "\t"} {print $2, $1}'
试试这个:
$ git rev-list --count --since=<start-date> --before=<end-date> <ref>
例如,要获取当前分支昨天完成的提交数量:
$ git rev-list --count --since=yesterday --before=today HEAD
也接受绝对日期:
$ git rev-list --count --since=2016-03-02 --before=2016-03-03 HEAD
我尝试过:
git 日志 | grep 日期 | awk '{print " : "$4" "$3" "$6}' | uniq-c
而且它有效。你会得到类似的信息:
5 : 3 Mar 2016
4 : 2 Mar 2016
8 : 1 Mar 2016
[...]
我找到了命令这里。
使用 Git 2.39(2022 年第 4 季度),您还有另一种选择,因为“
git shortlog
”(man) 学会了按格式字符串进行分组。
请参阅 commit 7b11234、commit 9c10d4f、commit 10538e2、commit 3dc95e0、commit b017d3d、commit 0b293df(2022 年 10 月 24 日) 泰勒·布劳 (
ttaylorr
).peff
)的commit 251554c(2022 年 10 月 24 日)。
ttaylorr
-- 合并于 commit c112d8d,2022 年 10 月 30 日)
:支持任意提交格式shortlog
s--group
签字人:Taylor Blau
除了根据提交者、作者或一个或多个指定预告片中的身份生成短日志之外,基于任意提交格式生成短日志也很有用。
例如,这可以用于生成提交活动随时间的分布,如下所示:
$ git shortlog --group='%cd' --date='format:%Y-%m' -s v2.37.0.. 117 2022-06 274 2022-07 324 2022-08 263 2022-09 7 2022-10
(man)的默认行为(按提交作者计数)可以模拟如下:git shortlog
$ git shortlog --group='%aN <%aE>' ...
并且未来的补丁将使默认行为(以及
和--committer
)成为更灵活的--group=trailer:<trailer>
选项的特殊情况。--group
另请注意,
枚举值仅用于指定在标准输入模式下使用SHORTLOG_GROUP_FORMAT
来声明组合无效。--group:<format>
git shortlog
现在包含在其 手册页中:
)。与git log
一起使用很有用。--group=format:<format>
git shortlog
现在包含在其 手册页中:
,任何由format:<format>
选项接受的字符串 'git 日志'。 (参见“漂亮的格式”部分--format
。)git log
如@underscore_d的答案所示,使用以下命令,您可以请求每天提交的提交数量。
git log --date=short --pretty=format:%ad | sort | uniq -c
利用这个,我准备了每月和每年查询所需的命令。
使用 awk 命令,仅保留日期中的第 6 个和第 7 个字符,代表指示月份的数字。
git log --date=short --pretty=format:%ad | awk '{print substr($1, 6, 2)}' | sort | uniq -c
结果示例
12 01
60 02
12 03
13 04
10 05
74 06
24 07
30 08
10 09
12 10
89 11
46 12
使用 awk 命令,仅保留日期的前 7 个字符,代表指示年和月的数字。
git log --date=short --pretty=format:%ad | awk '{print substr($1, 1, 7)}' | sort | uniq -c
结果示例
1 2017-01
6 2017-02
12 2017-03
13 2017-04
10 2017-05
7 2018-01
5 2018-02
13 2019-08
4 2020-09
14 2020-10
2 2020-11
1 2020-12
使用 awk 命令,仅保留日期的前 4 个字符,代表指示年份的数字。
git log --date=short --pretty=format:%ad | awk '{print substr($1, 1, 4)}' | sort | uniq -c
结果示例
19 2017
42 2018
89 2019
3 2020