is there a way to count the number of commits in certain period (e.g. the last year from 2015-03-01 to 2016-03-01) for git (GitHub) repositories?
2 Answers
To count the commits in a date range in your current branch do this:
git rev-list --count HEAD --since="Dec 3 2015" --before="Jan 3 2016"
If you want the count for all branches in one go use --all additionally
git rev-list --count --since="Dec 3 2015" --before="Jan 3 2016" --all
if you want to exclude merge-commits, use option --no-merges
git rev-list --count --since="Dec 3 2015" --before="Jan 3 2016" --all --no-merges
-
2
You can get total number of commits through a time period with two different ways:
First way
Get the total commit by using [second - minute - hour - day - week - month - year]
Get the total commits by second
git rev-list --count HEAD --since=600.second
Get the total commits by minute
git rev-list --count HEAD --since=30.minute
Get the total commits by hour
git rev-list --count HEAD --since=3.hour
Get the total commits by day
git rev-list --count HEAD --since=28.day
Get the total commits by week
git rev-list --count HEAD --since=4.week
Get the total commits by month
git rev-list --count HEAD --since=1.month
Get the total commits by year
git rev-list --count HEAD --since=1.year
Second way
Using since and before - since take the start date and before take the end date that you want to get commit from it.
git rev-list --count HEAD --since="Dec 1 2021" --before="Jan 3 2022"
You can get all commits by selecting the branch name:
git rev-list --count master --since="Dec 1 2021" --before="Jan 3 2022"
-
How could I filter the commit messages? eg. I want the metrics for commits with a message that contains a common string Dec 9, 2022 at 15:43
-
You will use grep with log
git log --oneline |grep -i "put_string_here"
, you will put pattern between double quotation,-i
for ignore case sensitive. Dec 9, 2022 at 16:11