Git Course 0%

git show

Beginner Git CLI Safe ≈ 4 min

Summary: git show <commit> prints a commit's metadata, message and diff. git show <commit>:<path> prints a file exactly as it was in that commit.

Safe — read-only.

What it does

For a commit: what git log -1 shows, plus the changes it introduced (the diff against its parent), or only the file summary with --stat. For <commit>:<path>: the raw content of that file at that point, printed to the screen.

Why it exists

git log lists; git show opens one item. And reading an old version of a file without checking it out avoids the detached-HEAD detour.

When to use it

  • "What did this commit change?" after finding it in the log or in blame.
  • "What did this file say at release 1.2?": git show v1.2.0:docs/faq.md.
  • Saving an old version next to the current one for comparison: git show HEAD~5:data/trails.csv > old.csv.

When not to use it

  • To compare two arbitrary commits (use git diff a b).
  • To restore a file into the working tree (use git restore --source=<commit> <path>).

Syntax

Form Meaning
git show The commit at HEAD, with its diff
git show <hash> / <tag> / <branch> / HEAD~2 Any commit
git show --stat <commit> Files and line counts instead of the full diff
git show <commit>:<path> A file's content at that commit
git show <commit> -- <path> Only that file's part of the diff

Examples

Terminal
$ git show --stat HEAD
commit c541c807612e2b322396e0defbaa843bdc7a0a27
Author: Ana <ana@northwind-trails.example>
Date:   Mon Sep 7 09:30:00 2026 +0200

    docs: add maintainer note

 README.md | 2 ++
 1 file changed, 2 insertions(+)
Terminal
$ git show HEAD~2:data/trails.csv
name,region,distance_km,difficulty
Ridge Loop,North,7.5,moderate
…
Twin Falls Track,South,8.8,moderate

Without --stat, the diff follows the message; it is the same -/+ format as git diff.

Expected result

Text on screen; nothing changes. Long output opens the pager (q to quit).

Common mistakes

  • fatal: bad object or unknown revision: a typo in the hash, or a hash from another repository. Copy it from git log.
  • fatal: path 'x' exists on disk, but not in '<commit>': the file did not exist (or had another name) at that commit; check git log --follow -- <path>.
  • Forgetting the colon in <commit>:<path>, which makes Git look for a commit named like the path.

How to undo or recover

Nothing to undo.

In VS Code

Click a commit in the Source Control Graph or a Timeline entry to see its files and diffs; GitLens adds "Open File at Revision".

In IntelliJ IDEA

Select a commit in the Log tab: its files appear on the right; double-click one for the diff. Right-click a file → Git → Show History, select a revision → Open Repository Version.

git log finds the commit · git diff compares two commits · git blame finds the commit for a line · git restore --source brings an old version into the working tree.

Lessons that use this command

Reading history · Commits, hashes and history · Lab 1.

Key terms

Commit Hash (SHA) HEAD