Git Revision Syntax

Git revision selectors, ranges, parents, symbolic refs, and object/path addressing.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Commit Selectors
Current commit
git rev-parse HEAD

# Resolve HEAD to the current commit ID.

First parent of HEAD
git rev-parse HEAD^

# Resolve the first parent.

Second ancestor
git rev-parse HEAD~2

# Walk first-parent ancestry twice.

Nth parent of merge commit
git rev-parse HEAD^2

# Select second parent of a merge commit.

Resolve branch
git rev-parse main

# Resolve branch ref to commit ID.

Resolve tag dereferenced
git rev-parse v1.2.0^{}

# Dereference annotated tag to underlying object.

HEAD at earlier checkout time
git rev-parse "HEAD@{yesterday}"

# Resolve HEAD reflog entry by date expression.

Upstream branch
git rev-parse @{u}

# Resolve current branch upstream.

Push target
git rev-parse @{push}

# Resolve push destination ref for current branch.

## Revision Ranges
Commits reachable from right not left
git log main..feature/my-change

# Show commits in feature not in main.

Symmetric difference log
git log main...feature/my-change

# Show commits unique to either side.

Diff two branch tips
git diff main..feature/my-change

# Diff end states of two refs.

Diff feature against merge base
git diff main...feature/my-change

# Diff branch relative to common ancestor.

Exclude one ref
git log HEAD ^origin/main

# Commits reachable from HEAD but not origin/main.

Limit to ancestry path
git log --ancestry-path A..B

# Show only commits on ancestry chain between two points.

First-parent history
git log --first-parent main

# Follow merge history on the mainline.

## Path and Object Selection
Show file at HEAD
git show HEAD:README.md

# Print file content from a revision.

Show file from branch
git show feature/my-change:src/app.ts

# Read file content from another branch.

List tree entries
git ls-tree HEAD src/

# List files in a tree path.

Show object type
git cat-file -t HEAD^{tree}

# Inspect object type after rev resolution.

Pretty-print object
git cat-file -p HEAD^{tree}

# Display tree or commit content.

Verify ref syntax
git rev-parse --verify feature/my-change^{commit}

# Require object to resolve to a commit.

## Special Selectors and Search
Search all refs by message
git log --all --grep="security fix"

# Find commits across all refs matching message text.

Follow renamed file history
git log --follow -- path/to/file

# Continue file history across renames.

Topological ordering
git log --topo-order --graph --oneline

# Display commit graph respecting topology.

List commits with parents
git rev-list --parents -n 5 HEAD

# Include parent IDs in output.