Git commit count a day

梦想的初衷 提交于 2019-12-30 08:15:30

问题


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 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.



回答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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!