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

Single commit selection syntax and symbolic refs.

Current commit

Resolve HEAD to the current commit ID.

bashANYrevisionhead
bash
git rev-parse HEAD

First parent of HEAD

Resolve the first parent.

bashANYrevisionparent
bash
git rev-parse HEAD^

Second ancestor

Walk first-parent ancestry twice.

bashANYrevisionancestor
bash
git rev-parse HEAD~2

Nth parent of merge commit

Select second parent of a merge commit.

bashANYrevisionmerge
bash
git rev-parse HEAD^2

Resolve branch

Resolve branch ref to commit ID.

bashANYrevisionbranch
bash
git rev-parse main

Resolve tag dereferenced

Dereference annotated tag to underlying object.

bashANYrevisiontag
bash
git rev-parse v1.2.0^{}

HEAD at earlier checkout time

Resolve HEAD reflog entry by date expression.

bashANYrevisionreflog
bash
git rev-parse "HEAD@{yesterday}"

Upstream branch

Resolve current branch upstream.

bashANYrevisionupstream
bash
git rev-parse @{u}

Push target

Resolve push destination ref for current branch.

bashANYrevisionpush
bash
git rev-parse @{push}

Revision Ranges

Compare sets of commits using dots, exclusions, and ancestry operators.

Commits reachable from right not left

Show commits in feature not in main.

bashANYrevisionrange
bash
git log main..feature/my-change

Symmetric difference log

Show commits unique to either side.

bashANYrevisionrangesymmetric
bash
git log main...feature/my-change

Diff two branch tips

Diff end states of two refs.

bashANYrevisiondiff
bash
git diff main..feature/my-change

Diff feature against merge base

Diff branch relative to common ancestor.

bashANYrevisionmerge-base
bash
git diff main...feature/my-change

Exclude one ref

Commits reachable from HEAD but not origin/main.

bashANYrevisionexclude
bash
git log HEAD ^origin/main

Limit to ancestry path

Show only commits on ancestry chain between two points.

bashANYrevisionancestry
bash
git log --ancestry-path A..B

First-parent history

Follow merge history on the mainline.

bashANYrevisionfirst-parent
bash
git log --first-parent main

Path and Object Selection

Address blobs, trees, and paths inside specific revisions.

Show file at HEAD

Print file content from a revision.

bashANYrevisionpathblob
bash
git show HEAD:README.md

Show file from branch

Read file content from another branch.

bashANYrevisionpath
bash
git show feature/my-change:src/app.ts

List tree entries

List files in a tree path.

bashANYrevisiontree
bash
git ls-tree HEAD src/

Show object type

Inspect object type after rev resolution.

bashANYrevisionobject
bash
git cat-file -t HEAD^{tree}

Pretty-print object

Display tree or commit content.

bashANYrevisionobject
bash
git cat-file -p HEAD^{tree}

Verify ref syntax

Require object to resolve to a commit.

bashANYrevisionverify
bash
git rev-parse --verify feature/my-change^{commit}

Special Selectors and Search

Commit selectors using message, path, and regex helpers.

Search all refs by message

Find commits across all refs matching message text.

bashANYrevisionsearchgrep
bash
git log --all --grep="security fix"

Follow renamed file history

Continue file history across renames.

bashANYrevisionpathfollow
bash
git log --follow -- path/to/file

Topological ordering

Display commit graph respecting topology.

bashANYrevisiongraph
bash
git log --topo-order --graph --oneline

List commits with parents

Include parent IDs in output.

bashANYrevisionparents
bash
git rev-list --parents -n 5 HEAD