Command Reference

git-rev-list Tutorial

Explains how to use git-rev-list to enumerate commit sets in a script-friendly way.

Who This Is For
  • Developers who already know basic commit and branch actions
  • Readers who want to understand command boundaries and risk
Prerequisites
  • A basic mental model of worktree, index, and commits
  • Comfort reading `git status` and a small commit graph
Common Risks
  • Using local cleanup commands on already shared history
  • Continuing to rewrite before confirming a recovery path

The short version

git-rev-list is used to enumerate commit sets in a script-friendly way.

When it is a good fit

  • when you need to enumerate commit sets in a script-friendly way
  • when you want this step to be repeatable instead of ad hoc
  • when you need a clearer mental model of what Git is recording or updating

Basic example

git rev-list --count HEAD

What to watch most closely

Plumbing commands are closer to Git internals, so check whether a safer high-level command already solves the problem.

A safer working habit

Treat it as a read-only inspection tool first, then move to write-oriented usage only when necessary.

Useful angles for understanding it

  • Inspect lower-level objects and refs
  • Write scripts or debug advanced issues
  • Verify internal repository state

Related reading

Read it alongside git status, git log, and git show so it is easier to see how the command changes history, refs, the index, or the working tree.

What problem this command solves in a workflow

git rev-list solves the problem of "listing commits in a script-friendly way". It outputs commit hashes in a compact format, with rich range filtering and traversal options, making it the go-to tool for scripts and automation that process commit sets.

Typical use cases

  • Count commits between two versions by running git rev-list --count v1.0..v2.0 to get an exact number.
  • Iterate over all commits on a branch in a CI script by using git rev-list main to output a list of commit hashes.
  • Find a commit that introduced a problem by using git rev-list --ancestry-path OLD..NEW to limit the commit range.

Diagram view

Enumerate commits in a script-friendly wayrev-list reads commit history and outputs commit hashes for a given range. It is a pure read-only operation that never modifies the repository.
Commit range
Start commitEnd commitPath filterTraversal options
Outputs
Commit hash listCommit countFirst/newest commit
rev-list outputs plain-text hash lists, ideal for piping to other commands in scripts.

Special cases and boundaries

  • git rev-list is a pure read-only command — it never modifies the repository, index, or working tree.
  • By default it outputs in reverse chronological order (newest first); use --reverse to flip the order.
  • The output format is very compact (one hash per line) — unlike git log, it does not include commit messages or other human-readable details.
  • Rich filtering options are available: --count outputs only the number, --max-count limits output, and --after/--before filter by date.
  • For very large repositories, output can be extremely long — consider using --count or --max-count to limit the volume.