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 HEADOptions
| Flag | What it does |
|---|---|
| --count | Print the number of commits, not SHAs |
| --left-right | Mark which side of a symmetric range |
| --max-count=<n> | Limit how many commits |
| --no-merges | Exclude merge commits |
| --all | Start 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
git log: Usage, Options & Common CI Errorsgit log shows commit history with flexible formatting. Reference for --oneline, --graph, --pretty, ranges, an…
git merge-base: Usage, Options & Common CI Errorsgit merge-base finds the common ancestor of two commits, the basis for diffing a PR. Reference for --fork-poi…
git rev-parse: Usage, Options & Common CI Errorsgit rev-parse resolves refs to SHAs and reports repo paths - core CI plumbing. Reference for --short, --abbre…
git fetch: Usage, Options & Common CI Errorsgit fetch downloads remote objects and refs without touching your working tree. Reference for --depth, --unsh…