Reviewing a single commit
After git bisect or git log finds a suspicious commit, run git show <hash> to read its message and exact changes before you report or revert it.
Git · Command
git show prints one or more Git objects in a readable form: a commit, an annotated tag, a tree, or a blob. With no argument it shows HEAD, the latest commit on the current branch.
Last updated
You pass git show any object names (revisions). Git resolves each one and chooses the output by object type. A commit shows its log message and a patch. A merge commit shows a dense combined diff by default. A tag shows the tag message and then the object it points to. A tree shows a list of names, and a blob shows its raw contents. Display options come from the git log and git diff machinery. Use --pretty or --format to control the header, and use -s, --stat, --name-only or --diff-merges to control the diff part.
git show [<options>] [<object>…]| Name | Type | Description |
|---|---|---|
<object>... | revision / object name | One or more objects to show. Defaults to HEAD. Any form from gitrevisions works, such as hashes, branches, tags, HEAD~2, or <rev>:<path>. |
--pretty[=<format>] / --format=<format> | string | Sets the commit header layout. It can be oneline, short, medium (the default), full, fuller, reference, email, raw, or a custom format:/tformat: string. |
--abbrev-commit / --oneline | flag | Shows a short unique hash prefix instead of the full hash. --oneline is the same as --pretty=oneline --abbrev-commit. |
-s / --no-patch | flag | Hides the diff output and keeps only the commit or tag information. |
--diff-merges=<format> | string | Sets how merge commits are diffed. Options are off, on, first-parent, separate, combined, dense-combined, and remerge. |
--stat / --name-only / --name-status | flag | Shows a summary of the changed files instead of the full patch. |
--show-signature | flag | Checks the commit's GPG signature and prints the result. |
The rendered objects are written to stdout: commit headers and diffs, tag messages, tree entry names, or raw blob contents.
#!/usr/bin/env bash
set -euo pipefail
# Latest commit with full patch
git show
# Only the subject and author of the previous commit, no diff
git show -s --format='%h %an: %s' HEAD~1
# Files changed by a commit, with diffstat
git show --stat HEAD
# Annotated tag message plus the commit it points to, names only
git show --name-status v1.0.0
# Contents of a file as it was two commits ago (blob output)
git show HEAD~2:README.md > README.old.md
# How conflicts were resolved in a merge commit
git show --remerge-diff HEAD
# Verify the signature of the tip commit
git show --show-signature -s HEADThese commands show git show used on commits, a tag, and a blob, with options that trim, summarize, or verify the output.
After git bisect or git log finds a suspicious commit, run git show <hash> to read its message and exact changes before you report or revert it.
Write a file's content from an earlier revision to disk with git show <rev>:<path>, without checking out that revision or touching the working tree.
In a CI step, use git show -s --format=... on a tag to pull the commit subject, author, and date into a changelog.
Use --remerge-diff or --diff-merges=first-parent to see what a merge commit actually introduced, or how its conflicts were resolved.
It looks at the type of each object you name. A commit shows its log message and diff. A tag shows its message and the object it references. A tree shows its entry names, and a blob shows its contents. With no arguments, the object defaults to HEAD.
Follow-up: What does git show v1.0.0^{tree} print? It peels the tag down to the root tree of the tagged commit and lists that tree's entry names, with no commit header or diff.
Use git show -s --format=%s <rev>. The -s flag (--no-patch) turns off the diff output, and --format chooses which commit fields to print. Prefer tformat:, or a bare %-string, which is treated as tformat:, so each entry ends with a newline.
Follow-up: Why does --format=%s end with a newline when --format=format:%s might not? A bare string containing % is treated as tformat:, which adds a terminator after each entry. format: only puts separators between entries.
By default it prints a dense combined diff (--cc). This shows only the hunks where the merge result differs from every parent. You can change it with --diff-merges, for example first-parent, separate, combined, remerge, or off, or with shortcuts like --dd or --remerge-diff.
Follow-up: When is --remerge-diff more useful than --cc? When you want to see how a person resolved conflicts. It re-runs the merge into a temporary tree, which may contain conflict markers, and diffs that against the committed result.
git loggit diffgit ls-treegit cat-filegit notesgit rev-parsegitrevisions