Git: count commits with rev-list - Adam Johnson (original) (raw)
2024-11-20
git rev-list lists details about commits (also known as “revisions”, hence the name). Its --count
option outputs the count of commits in the given range. Pass it @
, the short alias for HEAD
, to count commits on the current branch:
$ git rev-list --count @ 707
On a branch
To count commits on a branch, specify the branch’s commit range using the <base>..<branch>
syntax. For example, to count commits on the feature branch bucket
that is forked off main
:
$ git rev-list --count main..bucket 5
If you’re currently on the bucket
branch, you can omit its name:
$ git rev-list --count main.. 5
Likewise, if you’re on main
, you can omit its name:
$ git rev-list --count ..bucket 5
The opposite count is also possible: the count of commits on main
not present on bucket
. Just swap the branch names so bucket
is first:
$ git rev-list --count bucket..main 17
It looks like bucket
needs updating with a merge or rebase!
Limited time
git rev-list
supports the same set of commit-limiting options as git log
. For example, use --since
to count commits since a certain date:
$ git rev-list --count --since yesterday 11
$ git rev-list --count --since 1.week.ago 64
Grouped by author or day
To group up counts by different dimensions, you’ll want the git shortlog
command. For example, to count commits by author:
$ git shortlog -ns --since yesterday 6 Gordyn 5 Scribbles
See my previous post for more on that.
Fin
May your commits be many and your conflicts few,
—Adam
🎉 My book Boost Your Git DX was updated on January 28th!
One summary email a week, no spam, I pinky promise.
Related posts:
Tags: git