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 uthor d ate $ c>。如果需要,您可以使用 cd 代替 c mmit d ate,但是一旦您樱桃采摘变基等,它就会变得有用得多。

  • |。 uniq 需要sort ,因为它仅检查相邻的重复项。当然,我们几乎肯定希望无论如何都要在最后对日期进行排序。

  • | uniq -c 计算每个 YYYY-MM-DD 的相邻重复项的数量,并将其加到日期之前。

  • 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'

就是这么简单...!

或者,避免发疯,只需使用 awk 而不是 sed

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

awk 'BEGIN{OFS = "\t"} {print $2, $1}'