π¬ 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
Option | Description |
---|---|
--stat | Summary of file changes |
--name-only | Show only names of changed files |
--name-status | Show changed file names with status (A, M, D) |
--oneline | Display commit hash and message on one line |
--pretty=format:"..." | Customize commit log output |
--quiet | Suppress 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
Command | Description |
---|---|
git show | Show latest commit details |
git show <commit> | Show specific commit |
git show HEAD~2 | Show third-last commit |
git show --stat | Show commit summary |
git show <commit>:<file> | Show file content at commit |
git show v1.0.0 | Show annotated tag details |
git show --name-only | Only 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 :