What does git shortlog -sn report, and when would you use it?
answer
- Same history, grouped by person
- Summary mode replaces subjects with counts
- Numbered mode sorts by that count
- Accepts a revision range like a release span
- Identities need a mailmap to merge
basics
~20 sgit shortlog groups commits by author. With -s it prints only counts instead of subjects, and -n sorts by descending count, so git shortlog -sn is a per-author commit tally; add a revision range to scope it to a release.
solid answer
~40 s`git shortlog` takes the same history `git log` would traverse and groups it by author, printing each author followed by their commit subjects — which is where the "here is what went into this release" changelog shape comes from. `-s` (`--summary`) suppresses the subjects and prints just a count per author, `-n` (`--numbered`) sorts by that count rather than alphabetically, and `-e` (`--email`) includes addresses, which matters when one person commits under two identities. Scope it with a revision range like `git shortlog -sn v1.0..v2.0`, and add `--no-merges` to exclude merge commits. Recent Git also has `--group`, so you can group by committer or by a message trailer instead of the author. The obvious caution: commit counts measure activity, not contribution.
code
console · 6 lines$ git shortlog -sn v1.0..v2.0
42 Jane Doe
17 Sam Patel
3 Alex Kim
$ git shortlog -sne --no-merges --since='6 months ago'go deeper
Know the shape of the output: authors with counts when you pass -s, sorted by count when you add -n. Being able to produce a per-author tally for a release range is the whole ask here.
Explain that it groups the same traversal git log would perform, accepts revision ranges and log filters, reads from standard input when piped, and groups by the raw author string unless a mailmap normalises identities.
Use it as a signal rather than a score: spot single-contributor components and bus-factor risk, exclude merges for meaningful counts, and say plainly why commit counts are not a productivity measure.
Tie it to convention. Grouping by commit trailers only works if the team records them, so the value of these queries is downstream of the commit metadata standards you choose to enforce.
## What shortlog is for `git shortlog` is `git log` output reorganised by person. Instead of a chronological stream, it prints a block per author: the author's name, then their commit subjects indented beneath it. That format was designed for release announcements — the classic "changes in this release, by contributor" section — and it remains the fastest way to produce one. ## The flags - `-s` / `--summary` — drop the subjects and print only the number of commits per author. - `-n` / `--numbered` — sort by commit count, descending, instead of alphabetically by name. - `-e` / `--email` — include each author's email address in the heading. This is how you spot the same human appearing twice under different identities. - `--no-merges` — exclude merge commits, which otherwise inflate the counts of whoever integrates branches. So `git shortlog -sn` is the commonly typed combination: a ranked tally. `git shortlog -sne` adds emails to that tally. ## Scoping it With no arguments and a terminal on standard input, shortlog summarises the current branch's history. Give it a revision range and it summarises that range instead — `git shortlog -sn v1.0..v2.0` is the per-author breakdown of a release. It also accepts the same filters as log, so `git shortlog -sn --since='3 months ago'` works. A useful mechanical detail: when no revisions are given and standard input is not a terminal, shortlog reads log output from standard input. That means `git log --oneline --no-merges v1.0..v2.0 | git shortlog` is valid, and more generally you can shape the traversal with the full power of `git log` and then hand the result to shortlog for grouping. ## Grouping by something other than the author Recent Git supports `--group=<type>`, where the type can be `author`, `committer`, or `trailer:<token>`. Grouping by a trailer is the interesting one: if your project uses `Co-authored-by` or `Reviewed-by` trailers, `--group=trailer:Reviewed-by` produces a tally of reviewers rather than authors. That turns shortlog from a vanity counter into a way to query whatever structured metadata your commit convention records. ## Identity is messy Authors are grouped by the exact author string, so `Jane Doe <[email protected]>` and `jane <[email protected]>` are two people as far as shortlog is concerned. Git's mailmap mechanism exists to fix this: a `.mailmap` file maps alternative names and addresses onto canonical ones, and shortlog honours it. Without a mailmap, per-author numbers from a long-lived repository are essentially always wrong at the margins. ## The caution that belongs in the answer Commit counts are a measure of commit-making, not of contribution. A single commit can be a rewrite of a subsystem, and a hundred can be typo fixes; squash-oriented and merge-oriented workflows produce wildly different counts for identical work. Shortlog is excellent for changelogs, for finding out who knows a subsystem, and for spotting bus-factor concentration — and it is a bad performance metric. An interviewer who asks about it is often listening for whether you volunteer that distinction unprompted. ## Where it fits Use it when the question is "who" rather than "what": drafting release notes, working out whom to ask about an unfamiliar area, or checking whether a component has exactly one contributor. When the question is "what changed", stay in `git log`.
- Why does the same person sometimes appear twice in shortlog output?Grouping is by the exact author string, so a different name spelling or a different email address creates a separate group. Git's mailmap mechanism exists for this: a .mailmap file maps alternative identities onto canonical ones, and shortlog honours it, which is why long-lived projects maintain one.
- What is wrong with using shortlog counts as a productivity measure?A commit is not a unit of work. One commit can be a subsystem rewrite and a hundred can be typo fixes, and squash-oriented versus merge-oriented workflows produce completely different counts for identical output. It is a good tool for changelogs and for finding subject-matter owners, and a poor performance metric.
- How do you produce release notes for just the changes between two tags?Give shortlog the range: git shortlog --no-merges v1.0..v2.0 prints each author with their commit subjects beneath, which is the traditional release-note shape. Dropping -s keeps the subjects; --no-merges removes integration commits that carry no content of their own.
saying these in an interview costs you the question
- Treats commit counts as a measure of individual productivity
- Assumes shortlog shows the diff of each change
- Does not realise identities need a mailmap to be merged
- Thinks it always summarises the whole repository regardless of arguments
- Confuses it with a per-file ownership report