📚 Advanced Git & GitHub Topics
Estimated reading: 5 minutes 348 views

Git Show – Display Commit Details, Changes, and Metadata


Introduction – Why Use git show?

Need to inspect the full details of a commit—who made it, when, and what exactly changed? That’s what git show is for.

git show is a powerful Git command that allows you to display detailed information about a specific commit, including:

  • Commit message
  • Author and date
  • Diff of changes introduced in the commit

In this guide, you’ll learn:

  • What git show does
  • How to use it with commits, branches, and files
  • Output structure and formatting
  • Useful flags and options
  • Real-world scenarios and troubleshooting

What Is git show?

git show displays one or more Git objects, primarily commits. It’s most commonly used to inspect a single commit’s metadata and code changes.

It combines the output of:

  • git log -1 (commit info)
  • git diff (code changes)

Basic Syntax

git show [<object>]

Where <object> is typically a commit hash, branch name, tag, or even HEAD.


Default Output Structure

Example:

git show 3f7a1e2

Output:

commit 3f7a1e2b12c9a8d987a9c1a9b19ef0a2a3b01dce
Author: John Doe <john@example.com>
Date:   Mon Jun 16 10:20:42 2025 +0530

    Fix: handle login timeout error on mobile

diff --git a/login.js b/login.js
index abcd123..efgh456 100644
--- a/login.js
+++ b/login.js
@@ -15,7 +15,9 @@ function login() {
-    timeout = 3000;
+    timeout = 5000;
+    logError("Timeout updated for mobile devices");

Sections:

  • Commit metadata (hash, author, date)
  • Commit message
  • Unified diff output (actual code changes)

Common Examples and Use Cases

1. Show the Latest Commit

git show
# or
git show HEAD

Displays details for the tip of the current branch.


2. Show a Specific Commit by Hash

git show 3f7a1e2

Use partial or full hash to inspect that commit’s changes.


3. Show a Commit on Another Branch

git show feature-branch
# or
git show origin/main

Useful for previewing remote or unmerged commits.


4. Show a File’s Change in a Commit

git show 3f7a1e2:path/to/file.txt

Outputs the snapshot of that file in the given commit.


Useful git show Options

OptionDescription
--statSummary of file changes
--name-onlyShow only names of changed files
--name-statusShow changed file names with status (A, M, D)
--onelineDisplay commit hash and message on one line
--pretty=format:"..."Customize commit log output
--quietSuppress diff output

Example with --stat:

git show --stat HEAD

Output:

 login.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Show Specific Objects with Git Show

Git can inspect not just commits, but also other Git objects:

Show File in a Specific Commit:

git show 3f7a1e2:README.md

Show Tag Details:

git show v1.0.0

If the tag is annotated, this shows metadata and commit.


Common Pitfalls and Fixes

  • “fatal: bad object” error – Make sure the commit hash or reference exists.
  • Too much output – Use --name-only or --stat to reduce noise.
  • Misinterpreting diff – Remember: lines starting with + are additions, - are deletions.

Best Practices for Using git show

  • Use it before code review to inspect what exactly changed.
  • Combine with --name-status for quick summaries.
  • Use git show <commit>:<file> to recover or copy old file versions.
  • Pair with git log to traverse and inspect older changes.

GUI Tools for Commit Inspection

  • VS Code Source Control View – Click a commit to see full metadata and file diff.
  • Sourcetree – Commit detail pane shows what git show does.
  • GitKraken – Visual commit browser with inline diffs and history.

Summary Table – Git Show Commands

CommandDescription
git showShow latest commit details
git show <commit>Show specific commit
git show HEAD~2Show third-last commit
git show --statShow commit summary
git show <commit>:<file>Show file content at commit
git show v1.0.0Show annotated tag details
git show --name-onlyOnly show file names changed

Summary – Git Show

git show is the perfect tool for investigating commits deeply—from who made them, when they were made, and exactly what changed. Whether you’re debugging, reviewing, or restoring, it’s an essential Git command for any developer.

Key Takeaways:

  • Use git show to view full commit details and code diffs.
  • Add options like --stat or --name-only to simplify output.
  • Retrieve old file versions using git show <commit>:<file>.

Real-World Relevance: In daily dev work and release management, git show is key for code reviews, bug investigations, and commit audits.


Git Show — Frequently Asked Questions (FAQs)

How do I view the last commit in Git?
Use:

git show
# or
git show HEAD

How do I see just the commit message and files changed?
Use:

git show --name-only

Can I view the content of a file in a specific commit?
Yes:

git show <commit>:<path/to/file>

How can I see only which files were modified in a commit?
Use:

git show --name-only <commit>

Is git show the same as git log -p?
Not exactly. git log -p shows a series of commits, while git show shows one commit.


Share Now :
Share

Git Show

Or Copy Link

CONTENTS
Scroll to Top