← Back to Git Course | Chapter 2: Basic Commands | Lesson 13 of 18

Git show Command

git show is like opening one photo in the album and looking closely: it tells who took it, when, the caption, and exactly what changed in it.
Syntax
bash
git show [commit_hash]
git show commit_hash:file_name

Showing the Last Commit

git show with no arguments displays everything about your most recent commit -- author, date, full message, and the exact patch (line-by-line code changes) it introduced -- in one combined view.

Example: Showing the Last Commit

bash
git show

Showing a Specific Commit

Passing a specific commit hash or tag name, like git show a1b2c3d, lets you inspect any point in your project's history the same way, not just the latest commit.

Example: Showing a Specific Commit

bash
git show a1b2c3d

Showing a File at a Specific Commit

git show <commit>:<path/to/file> prints a file's exact contents as they existed at that specific commit, without checking out that commit or disturbing your current branch or working files at all.

Example: Showing a File at a Specific Commit

bash
git show a1b2c3d:path/to/file.txt

Customizing the Output Format

If you only care about which files changed rather than the full line-by-line patch, git show --stat swaps the detailed diff for a compact summary of insertion/deletion counts per file.

Example: Customizing the Output Format

bash
git show --stat

Showing File Names and Status

git show --name-only goes even further, listing just the filenames that were added, modified, or deleted in that commit -- useful for a quick glance at a commit's scope before diving into the actual changes.

Example: Showing File Names and Status

bash
git show --name-only
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Running git show and expecting the working directory changes, when it shows a committed snapshot and its diff.
  2. Passing only part of a hash that is too short or ambiguous, so Git reports an ambiguous argument.
  3. Forgetting the colon in git show a1b2c3d:file.txt, so Git treats file.txt as a separate path instead of showing the file's contents.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.