Skip to content
masterclass Buddy

Git · Command

git show

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

How it works

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.

Syntax

git show [<options>] [<object>…]

Parameters

NameTypeDescription
<object>...revision / object nameOne 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>stringSets 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 / --onelineflagShows a short unique hash prefix instead of the full hash. --oneline is the same as --pretty=oneline --abbrev-commit.
-s / --no-patchflagHides the diff output and keeps only the commit or tag information.
--diff-merges=<format>stringSets how merge commits are diffed. Options are off, on, first-parent, separate, combined, dense-combined, and remerge.
--stat / --name-only / --name-statusflagShows a summary of the changed files instead of the full patch.
--show-signatureflagChecks the commit's GPG signature and prints the result.

Returns

The rendered objects are written to stdout: commit headers and diffs, tag messages, tree entry names, or raw blob contents.

Key points

  • For a tree object, git show lists only the entry names, the same output as ls-tree with name-only. For more detail about a tree, use ls-tree directly.
  • For a blob, git show prints the file contents with no headers. This lets you redirect an old version of a file straight into a new file.
  • When you show an annotated tag, you see the tag's own message first and then the object it points to. For a tag that points to a commit, that means the commit and its diff.
  • git show uses the git log options for formatting, so placeholders like %h, %an, %s and %ad work in --format.
  • Add -s (or --no-patch) when you want only the metadata without the diff. This also cancels a --patch or --stat set earlier, for example in an alias.
  • --remerge-diff redoes a two-parent merge in a temporary tree and diffs that result against the real merge commit. This shows how the conflicts were resolved by hand.
  • --show-signature runs gpg verification on a signed commit and prints the result next to the normal output.

Common mistakes

  • The man page lists only the most common options. Many other options come from git log and git diff, so check those pages as well.
  • Passing -m alone prints nothing for merges. You must also pass -p, or use --diff-merges=on.
  • format: puts a separator between entries, so the last line may have no trailing newline. tformat: adds a newline after each entry, which suits scripts better.
  • If re-encoding the commit message fails, Git prints the original bytes without any warning. Invalid sequences can end up in your output.

Example: Inspecting commits, tags and old file versions

#!/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 HEAD

These commands show git show used on commits, a tag, and a blob, with options that trim, summarize, or verify the output.

When to use it

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.

Recovering an old file version

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.

Scripting release notes

In a CI step, use git show -s --format=... on a tag to pull the commit subject, author, and date into a changelog.

Auditing merge resolutions

Use --remerge-diff or --diff-merges=first-parent to see what a merge commit actually introduced, or how its conflicts were resolved.

Interview questions

QHow does git show decide what to print, and what does it show when you give no arguments?

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.

QHow would you print just the subject line of a commit, with no diff, in a script?

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.

QWhat does git show print for a merge commit by default, and how can you change it?

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 log
  • git diff
  • git ls-tree
  • git cat-file
  • git notes
  • git rev-parse
  • gitrevisions

Source: Git - git-show Documentation. Checked 2026-11-02.