Table of Contents

  1. Options
  2. Using date ranges
  3. Using commit ranges
  4. And more

TIL: Git shortlog

TIL, Git

April 27, 2020

Let’s say you’re working with a Git repository, and you want to see a summary of the commits. One way is to do git log, but that lists all of the commits. What if you wanted to summarise the commit history in some way, e.g. to determine the amount of commits per author, or see who has committed during a certain timespan? Enter git shortlog, a way to summarise git log output.


Without any options, git shortlog prints out the commits in the repository, grouped and sorted by author (and in parentheses, the number of commits per author). For example, here’s an excerpt of what it shows in the homebrew-core repository, which will be used as a running example in this post:

(@ivanvc) (2):
      Wrong architecture for OS X 10.5
      This flag causes the make process to fail

(@rkmathi) (1):
      sbt: don't use Java 8 incompatible flag.

If you want just a summary of the commit counts per author, you can use the -s flag:

2	(@ivanvc)
1	(@rkmathi)
1	-

You can sort by number of commits per author with the -n flag, so the output of git shortlog -sn is:

67114	BrewTestBot
16338	ilovezfs
5449	Mike McQuaid

You could also show committer information instead of author information, with the -c flag. As an aside, the author is the one who wrote the code (specified with --author=) and the committer is the one who created the commit. If you commit code without any flags, by default you’re both the author and the committer. So the output of git shortlog -csn is:

33979	FX Coudert
31092	ilovezfs
18378	Mike McQuaid

Using date ranges

Similar to git log, you can add a time/date range. For example, to answer the question “how many commits were created since 3 PM yesterday, and by whom?”, I could run

git shortlog -scn --since="3pm yesterday"

which reads as “summarize (-s) the committer information (-c), and sort by the number of commits (-n) since 3 PM yesterday”, and produces the following output:

77	BrewTestBot
25	Bo Anderson
12	GitHub

Or, to find out who authored code during the weekend, and in how many commits, I could run:

git shortlog -sn --since="last saturday" --until="last sunday"

which reads as “summarize (-s) the author information (implicit), and sort by the number of commits (-n) between last saturday and last sunday”, and produces the output:

67	Bo Anderson
43	Rui Chen
33	chenrui

Side note: for dates, make sure you set git config properly, because “by default, dates are shown in the original time zone (either committer’s or author’s)” (source), which is a bit inconsistent.

Using commit ranges

Like with git log, you can provide a commit revision range to only look at those commits. For example, I could ask to see all of the commits since the hash 49ab63ad28a8 with git shortlog 49ab63ad28a8..HEAD:

Bastian Hofmann (1):
      topgrade 4.3.1

Or, if I had just pulled from upstream and wanted to see the authors and their respective number of commits that are not yet present on my fork, I could use git shortlog thezeroalpha/master..master:

1	404NetworkError
1	Abraham Cruz Sustaita

Specifying revision ranges is out of the scope of this post (and perhaps a topic for a later post), but you can read more about it here.

And more

There’s a lot more you can do with git shortlog. You can list out the authors’ emails, use a custom format, wrap the output at a certain width, limit the output with custom patterns, print only merge commits…the list goes on. Read more in git help shortlog, or online at git-scm.