LinuxCommandLibrary

git-rev-list

List commit objects in reverse chronological order

TLDR

List all commits on the current branch

$ git rev-list [HEAD]
copy

Print the latest commit that changed (add/edit/remove) a specific file on the current branch
$ git rev-list [[-n|--max-count]] 1 HEAD -- [path/to/file]
copy

List commits more recent than a specific date, on a specific branch
$ git rev-list --since "[2019-12-01 00:00:00]" [branch_name]
copy

List all merge commits on a specific commit
$ git rev-list --merges [commit]
copy

Print the number of commits since a specific tag
$ git rev-list [tag_name]..HEAD --count
copy

SYNOPSIS

git rev-list [options] <commit-ish>...
git rev-list --walk-reflogs [options] <refname>...

PARAMETERS

--walk-reflogs
    Walk reflogs instead of the commit graph. Requires <refname> instead of <commit-ish>.

<commit-ish>...
    Specify starting points for the traversal. These can be commit SHAs, branch names, tags, or other references.

--all
    Show all reachable commits from all refs (branches, tags, remotes).

--branches[=pattern]
    Include all local branches (or those matching a specified pattern).

--tags[=pattern]
    Include all tags (or those matching a specified pattern).

--remotes[=pattern]
    Include all remote-tracking branches (or those matching a specified pattern).

--not <commit>
    Exclude commits reachable from the specified commit.

--since=<date>
    Limit commits to those newer than a specified date.

--until=<date>
    Limit commits to those older than a specified date.

--author=<pattern>
    Limit commits to those whose author matches the pattern.

--committer=<pattern>
    Limit commits to those whose committer matches the pattern.

--grep=<pattern>
    Limit commits to those whose log message matches the pattern.

--max-count=<number>
    Limit the number of commits to output.

--skip=<number>
    Skip a specified number of commits before starting to show the output.

--objects
    Print object IDs of referenced objects (trees, blobs) along with commit IDs.

--parents
    Print parent commit IDs after each commit ID.

--children
    Print child commit IDs after each commit ID (implies --topo-order).

--topo-order
    Output commits in topological order (parents before children).

--date-order
    Output commits in date order (newest first within common ancestors).

--reverse
    Output commits in reverse order (oldest first).

--left-right
    Mark which side of a symmetric difference the commit is on (< for left, > for right).

DESCRIPTION

git-rev-list is a low-level plumbing command in Git that lists commit objects, typically in reverse chronological order, starting from the specified points. It forms the core of many Git commands, most notably git log. Unlike git log, which is a porcelain command focused on user-friendly output, git-rev-list primarily outputs commit SHAs and is designed for scripting and internal Git operations. It offers extensive options for filtering, ordering, and selecting commits based on various criteria like author, committer, date ranges, commit message patterns, and reachability. Its power lies in its ability to precisely control which commits are included or excluded, making it invaluable for advanced repository analysis, custom logging, and complex merge strategies.

CAVEATS

git-rev-list is a plumbing command, meaning its output is designed for programmatic consumption, not human readability. For user-friendly output, consider using git log, which builds upon git-rev-list but provides rich formatting and filtering options. Using options like `--objects` can produce very verbose output.

PLUMBING VS. PORCELAIN

git-rev-list exemplifies a "plumbing" command, providing a low-level interface for internal Git operations. This contrasts with "porcelain" commands like git log, which are user-friendly interfaces built upon these plumbing commands. Understanding this distinction is key to leveraging Git effectively for scripting and automation.

SYMMETRIC DIFFERENCE

When comparing two branches, git-rev-list can be used to show commits unique to each side. For example, `git rev-list A...B` will show commits reachable from A or B but not from their common ancestor. This is often used with `--left-right` to distinguish which branch a commit originates from.

HISTORY

git-rev-list has been a fundamental component of Git since its early days, predating the more user-friendly git log. It was designed by Linus Torvalds as part of the initial Git toolkit, providing the core mechanism for traversing and filtering commit graphs. Its continued importance highlights Git's modular design, where complex porcelain commands are built upon simpler, powerful plumbing tools.

SEE ALSO

Copied to clipboard