πŸ“š Advanced Git & GitHub Topics
Estimated reading: 5 minutes 15 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 :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

Git Show

Or Copy Link

CONTENTS
Scroll to Top