By admin , 29 April 2026

Synopsis

git rev-list [<options>] <commit>...

Description

The git rev-list command emits the SHAs of commits reachable from one or more starting points, optionally excluding others. It is the workhorse behind git log, git bisect, and many other commands. With its many filters, it can answer "how many commits between A and B," "the SHA of the merge base," "all commits not on main," and so on.

In day-to-day use, git rev-list integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git rev-list --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.

Understanding how git rev-list interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git rev-list's side effects helps avoid all three.

When to Use

Power users and toolsmiths use rev-list in scripts. Day-to-day developers use git log, which is built on top of rev-list but produces human-friendly output.

Common Options

OptionDescription
--countPrint just the number of commits.
--max-count=<n>Limit how many commits to list.
--reverseOutput oldest first.
--no-mergesExclude merge commits.
--first-parentFollow only the first parent of each merge.
--ancestry-pathRestrict to commits between two endpoints.
--allInclude every ref as a starting point.

Examples

git rev-list --count HEAD
# Total number of commits reachable from HEAD

git rev-list main..feature
# SHAs unique to feature

git rev-list --no-merges --since="1 month ago" main
# Non-merge commits in the last month

git rev-list --max-parents=0 HEAD
# Find root commits (no parents)

Common Mistakes

Forgetting that ranges with two dots exclude commits reachable from the left side. --first-parent changes the meaning of "ancestry" significantly. On huge repos, unbounded rev-list can be slow — pair with --max-count or path filters.

Related Commands

git log, git rev-parse, git merge-base, git bisect