# Git Shortlog: commits per author

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/git-shortlog-full-en
`git shortlog -sn` counts commits per author (`-s`) and sorts by number of commits instead of by name (`-n`). The docs do not state the direction. In this run the author with more commits came first.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 3 tests were run, TE-72-A, TE-72-B and TE-72-C. The expected non-zero exit is TE-72-C (exit status 128). Every row has a recorded log, and the exit statuses and log hashes are in the evidence table.)

### TE-72-A: shortlog -sn lists authors with commit counts; the run shows the larger count first

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm one
printf 'b\n' >> f.txt; git commit -qam two
printf 'c\n' >> f.txt; GIT_AUTHOR_NAME=other git commit -qam three
```

Command:

```bash
git shortlog -sn HEAD | sed 's/^ *//'
```

Recorded output:

```
2	tester
1	other
```

Exit status: 0. The output matches the expected text written before the run. This is the status of sed, the last command in the pipe.

### TE-72-B: shortlog on an older revision counts only the commits reachable from it

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm one
printf 'b\n' >> f.txt; git commit -qam two
printf 'c\n' >> f.txt; GIT_AUTHOR_NAME=other git commit -qam three
```

Command:

```bash
git shortlog -sn HEAD~1 | sed 's/^ *//'
```

Recorded output:

```
2	tester
```

Exit status: 0. This status and the output match what was written before the run. The status is that of sed, the last command in the pipe.

### TE-72-C: expected non-zero exit: shortlog with a revision name that does not exist stops with a fatal error

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm one
```

Command:

```bash
git shortlog -sn nosuchrev
```

Recorded output: none, standard output was empty.

Standard error from the same run:

```
fatal: ambiguous argument 'nosuchrev': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
```

Exit status: 128. This status and the output match what was written before the run.

TE-72-B: by the setup, the history has two commits by tester and a newest commit by other. HEAD~1 leaves out the newest commit, so the only line is 2 tester. TE-72-C: git shortlog -sn nosuchrev exited with status 128. The first line of standard error is fatal: ambiguous argument 'nosuchrev': unknown revision or path not in the working tree.

## Limits

Authors are grouped by name. The same person with two different names is counted twice (not tested). The run sets author names through environment variables.

## Source

- https://git-scm.com/docs/git-shortlog

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-72-A` | shortlog -sn lists authors with commit counts; the run shows the larger count first | 0 | PASS | `6a19e498c0f7` |
| `TE-72-B` | shortlog on an older revision counts only the commits reachable from it | 0 | PASS | `7fefad0cb1d1` |
| `TE-72-C` | expected non-zero exit: shortlog with a revision name that does not exist stops with a fatal error | 128 | PASS | `9d8f5a780033` |

Recorded on: bash 5.1.16(1)-release; git version 2.34.1; Python 3.10.12. Locale C.UTF-8, TZ=UTC.
Every row has a recorded log holding the setup commands, the command, stdout, stderr and exit status. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [Git Grep: search tracked files](https://kairos-2z6s.onrender.com/res/git-grep-full-en)
- [Git Switch: change branches](https://kairos-2z6s.onrender.com/res/git-switch-full-en)
- [Git Stash: set aside uncommitted work](https://kairos-2z6s.onrender.com/res/git-stash-full-en)
- [Git Show: read one commit](https://kairos-2z6s.onrender.com/res/git-show-full-en)
- [Git Rm Cached: stop tracking a file and keep it on disk](https://kairos-2z6s.onrender.com/res/git-rm-cached-full-en)
