Skip to content
Git Basics: Summarize Commit Authors in a Chosen Range

Git Basics: Summarize Commit Authors in a Chosen Range

October 28, 2026

A release report often needs a compact list of contributors. shortlog groups commits by author, and an explicit revision prevents accidental reliance on standard input.

Prepare a scratch directory

Tested on Linux with Git 2.52.0 and GNU Bash 5.2.37. You need Bash, a text editor, the named runtime, and standard mktemp, rm, and rmdir utilities. The examples use only controlled local data; generated fixture directories are cleaned automatically.

Keep the same terminal open. Stop if setup fails, before saving the source:

start_dir="$PWD"
work_dir="$(mktemp -d)" || exit 1
cd -- "$work_dir" || exit 1

Run the example

Save this as demonstrate-shortlog.sh:

#!/usr/bin/env bash
set -euo pipefail
export LC_ALL=C
fixture_dir="$(mktemp -d)"
trap 'rm -rf -- "$fixture_dir"' EXIT
export GIT_CONFIG_NOSYSTEM=1
export GIT_CONFIG_GLOBAL=/dev/null
export GIT_AUTHOR_NAME='Example Author'
export GIT_AUTHOR_EMAIL='author@example.invalid'
export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
export GIT_AUTHOR_DATE='2026-10-28T00:00:00+00:00'
export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
git init -q -b main "$fixture_dir/repo"
cd -- "$fixture_dir/repo"
git config commit.gpgsign false
git config core.hooksPath /dev/null
git commit -qm 'First change' --allow-empty
git commit -qm 'Second change' --allow-empty
GIT_AUTHOR_NAME='Second Author' GIT_AUTHOR_EMAIL='second@example.invalid' \
    git commit -qm 'Third change' --allow-empty
printf 'Author counts:\n'
git shortlog -sne HEAD
printf 'Latest commit author:\n'
git shortlog -sne HEAD~1..HEAD
test "$(git rev-list --count HEAD)" -eq 3

Run it:

bash demonstrate-shortlog.sh

Observed output:

Author counts:
     2	Example Author <author@example.invalid>
     1	Second Author <second@example.invalid>
Latest commit author:
     1	Second Author <second@example.invalid>

Read the result

The first report includes all three reachable commits. -s suppresses subjects, -n orders by commit count, and -e includes email addresses. The explicit range in the second report includes only the latest commit.

Apply it carefully

Commit counts are not a measure of productivity or impact. Author and committer are different fields, and mailmap rules can unify identities. Check the selected range and privacy expectations before publishing contributor email addresses. These fixture addresses are reserved examples. Run this script from an ordinary shell with no repository-selection variables such as GIT_DIR or GIT_WORK_TREE set. All commits and cleanup stay inside the newly created temporary fixture.

The official reference describes the behavior and options. These checks cover the fixture above rather than every input or platform.

Clean up

Remove the saved source, return to the starting directory, then remove the empty practice directory:

rm -- demonstrate-shortlog.sh
cd -- "$start_dir" || exit 1
rmdir -- "$work_dir"
unset start_dir work_dir

If the directory is not empty, inspect its remaining contents rather than deleting unknown files.

Acknowledgements

This post was created with assistance from AI.

Last updated on