Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Inspecting History

git show command

Reference for git show: print a commit with its diff, view annotated tags, list trees, print file contents at any revision, and control the format of merge diffs.

git show prints one or more Git objects in a form people can read. Give it a commit and it shows the message and the patch that commit introduced; give it a tag and it shows the tag message followed by the tagged object; give it a tree and it lists the entries; give it a blob and it prints the file as it was stored.

With no argument it shows HEAD. Because it accepts any revision syntax, git show HEAD~2:src/app.js is also the quickest way to read an old version of a file without checking it out. For ranges and history browsing use git log; git show is for looking at specific objects.

Terminal
git show
git show <commit>
git show <rev>:<path>

Try it

Bash Commits, statistics and file contents

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Tags, trees and merges

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
git show [<options>] [<object>...] [[--] <path>...]
Name Description
<object> A commit, tag, tree or blob. Several objects are shown one after another. Defaults to HEAD.
<rev>:<path> The blob or tree at that path in that revision.
:<path> The staged version of a file from the index.
-- <path>... Limit the patch of a commit to these paths.
-s, --no-patch Suppress the diff and show only the header and message.
--format=<fmt>, --pretty=<fmt> Choose the commit layout (see git log --pretty). --format= with an empty value prints nothing but the diff.
--stat, --name-only, --name-status, --word-diff Summaries and diff styles; all diff options are accepted.
--cc, -c, -m Merge diff styles: combined, dense-combined, or separate against each parent.
--first-parent With -m, diff only against the first parent.

Returns: exit status 0; 128 with fatal: when an object or path does not exist.

Usage notes

  • Object types decide the output. Commit: header, message and patch. Annotated tag: tagger, date and message, then the tagged object. Tree: tree <name>, a blank line, then the entry names (directories end with /). Blob: raw bytes.
  • Merges show a combined diff by default (--cc): only hunks that differ from all parents are shown, with two columns of +/- marks. Use -m to see each parent's diff separately.
  • Root commits are shown as if every file was added.
  • Binary files are printed raw for a blob, which may mess up a terminal; for a commit they appear as Binary files differ.
  • git show :path prints the staged version, useful to check what is about to be committed. :1:path, :2:path and :3:path name the conflict stages (see Revision syntax).
  • For scripts, prefer git cat-file to get exact object contents, and --format with -s to extract commit fields.