Git: count commits with rev-list

Like counting sheep!

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

By search term

Update (2025-07-03): Added this section.

Use --grep to count commits where the commit message matches a search term:

$ git rev-list --count --grep "Upgrade Django"
3

Multiple --grep options are supported with OR semantics. Add --all-match to require all terms to match (AND semantics).

Flip the logic with --invert-grep to count commits that do not match the search term:

$ git rev-list --count --invert-grep --grep "Upgrade Django"
704

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


😸😸😸 Check out my new book on using GitHub effectively, Boost Your GitHub DX! 😸😸😸


Subscribe via RSS, Twitter, Mastodon, or email:

One summary email a week, no spam, I pinky promise.

Related posts:

Tags: