Git, how to find out the number of commits made in a specific month

Issue

How can I find out the number of commits made in a specific month, without using before/after in git log --after={somedate} --before={somedate} | wc -l ? (also I don’t know if this is correct)

Solution

Starting with the Git log output, we can specify a date range using the --since and --until command-line options.

For example, to get the commits from April 2020, you can use the following:

git log --since "APR 1 2020" --until "MAY 1 2020"

We can get the number of commits by counting the lines, but we must ensure that only one-line is printed per commit. This is possible using the --pretty=oneline git log formatter:

 git log --pretty=oneline

Finally, we can count the number of lines by piping our git log output from stdout to the wc shell executable. By default, this executable will count the number of characters, but can be configured to count lines using the -l command-line option:

wc -l

Answer

We configure git log to print the commits from a specified date range and ensure one-line is printed per commit. Then, we feed the log into a line counter and get our results:

 git log --since "APR 1 2020" --until "MAY 1 2020" --pretty=oneline | wc -l

Answered By – Trent

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published