Git Reference ยท Plumbing Commands
git rev-list command
Reference for git rev-list: list commit IDs in reverse chronological order, count commits, filter by range, author or path, and find root and merge commits.
git rev-list walks the commit graph starting from the revisions you give it and prints the IDs of the commits it visits, newest first. It is the engine underneath git log: both accept the same revision and filtering options, but rev-list prints only IDs and has extra options for scripts, such as --count, --objects and --parents.
Use it when you need to feed commit IDs to another command, count commits, or ask graph questions like "which commits are on this branch but not on main?".
git rev-list HEAD git rev-list --count main..feature git rev-list --max-parents=0 HEAD
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
git rev-list [<options>] <commit>... [-- <path>...]
| Option | Description |
|---|---|
<commit>... |
Start points. A..B means reachable from B but not A; A...B means reachable from one but not both. ^A excludes. |
--all, --branches, --tags, --remotes |
Start from every ref (or a namespace). |
-n <n>, --max-count=<n>, --skip=<n> |
Limit or skip commits. |
--count |
Print the number of commits instead of the IDs. |
--reverse |
Output oldest first (applied after limiting). |
--parents, --children |
Add parent IDs (or child IDs) after each ID. |
--merges, --no-merges, --min-parents=<n>, --max-parents=<n> |
Filter by number of parents. |
--first-parent |
Follow only the first parent of merges. |
--author, --committer, --grep, --since, --until, -i, -E |
Filter by metadata, as in git log. |
--objects, --objects-edge, --disk-usage |
Also list trees and blobs, or report their size. |
--left-right, --cherry-pick, --cherry-mark |
Mark sides of a symmetric range; skip equivalent patches. |
--topo-order, --date-order, --author-date-order |
Ordering. The default is reverse commit time. |
--format=<fmt> |
Like git log --pretty; adds a commit <id> line before each. |
Returns: commit IDs, one per line (or a number with --count).
Errors: a fatal error for unknown revisions; "bad revision" is the usual message.
Usage notes
- Default order is by commit date, not topology. With skewed clocks a parent can appear before its child; add
--topo-orderwhen a script relies on parents coming after children. --countwith--left-rightprints two numbers: commits only on the left, then only on the right.- Path limiting is expensive.
-- <path>makes Git simplify history by looking at trees; on huge histories a commit-graph file helps (seegit commit-graph). --objectslists every object needed to rebuild the history; it is howpack-objectsis fed, and--objects --not <remote>shows what a push would send.- Root commits:
--max-parents=0finds them; a repository can have several. rev-listvslog: uselogfor people,rev-listfor programs.git log --format=%Hgives the same IDs.
Related
git log,git rev-parse,git merge-base, Revision ranges- Lessons: Revisions, Log and show