Count All Git Commits in a Repo
This could be useful to compare activity across multiple repos.
Quick Jump: Demo Video
A while back I wrote a detailed guide on using
git shortlog to count commits for specific authors but this time around we’re going to focus on only getting the number of total commits.
Here’s a couple of examples:
# All branches.
git rev-list --count --all
# Currently checked out branch.
git rev-list --count HEAD
# Skip merge commits.
git rev-list --count HEAD --no-merges
# Only merge commits.
git rev-list --count HEAD --merges
There’s quite a lot of other flags you can use such as
--before to limit counts by date,
--author to limit by author and more. I covered these flags in the
shortlog post, they happen to apply to
When would you consider using these commands?
Here’s a couple of personal use cases that came up recently:
- I wanted to quickly see how many commits I’ve added to my assorted Docker web app example apps to see how much time I’ve been spending on them relative to each other
- A client had a number of services they’ve built over the years and we wanted to get an idea where devs were spending their time, using
--sincehere was useful to get recent vs lifetime stats
- 0:05 – A few examples
- 0:52 – Personal use case with my Docker example apps
- 1:54 – Figuring out which service developers are spending time on
When was the last time you used this command? Let us know below!