Skip to content
Latchkey

git rev-list: Usage, Options & Common CI Errors

git rev-list is the plumbing that enumerates commits - counting them, comparing branches, walking ranges.

rev-list powers ahead/behind counts and history walks in scripts. It is git log without the formatting.

What it does

git rev-list outputs commit SHAs reachable from given refs in reverse chronological order, with flags to count, limit, and compare ranges - the engine many porcelain commands sit on.

Common usage

Terminal
git rev-list --count HEAD                 # total commit count
git rev-list --count main..feature        # commits ahead
git rev-list --left-right --count main...feature   # behind<TAB>ahead
git rev-list --max-count=10 HEAD

Options

FlagWhat it does
--countPrint the number of commits, not SHAs
--left-rightMark which side of a symmetric range
--max-count=<n>Limit how many commits
--no-mergesExclude merge commits
--allStart from all refs

Common errors in CI

Counts are wrong or capped on a shallow clone because history is truncated - deepen with git fetch --unshallow or fetch-depth: 0. A symmetric range (A...B) needs both refs present, so fetch the target branch first.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →