show Git Command Guide
The git show command displays detailed information about Git objects including commits, tags, trees, and blobs. It provides comprehensive object inspection with formatting options for code review, debugging, and repository analysis.
git show Syntax:
Section titled “git show Syntax:”git show [<options>] [<object>...]Display Format Options:
Section titled “Display Format Options:”| Option | Description |
|---|---|
-p, --patch | Generate patch (default for commits) |
-s, --no-patch | Suppress diff output |
--format=<format> | Pretty-print with custom format |
--oneline | Show oneline format |
--name-only | Show only changed filenames |
--name-status | Show filenames with status |
--stat | Show diff statistics |
--numstat | Machine-readable diff statistics |
--shortstat | Summary of total changes |
Content Control Options:
Section titled “Content Control Options:”| Option | Description |
|---|---|
--abbrev-commit | Show abbreviated commit hashes |
--no-abbrev-commit | Show full commit hashes |
--oneline | Abbreviated commit + subject |
--encoding=<encoding> | Re-encode commit messages |
--expand-tabs[=<n>] | Expand tabs in output |
--no-expand-tabs | Don’t expand tabs |
--notes[=<ref>] | Show notes |
--no-notes | Don’t show notes |
--show-signature | Show signature status |
Diff Output Options:
Section titled “Diff Output Options:”| Option | Description |
|---|---|
-U<n>, --unified=<n> | Lines of context |
--raw | Generate raw diff format |
--patch-with-raw | Output both patch and raw |
--patch-with-stat | Output patch and stat |
--no-renames | Don’t detect renames |
--find-renames[=<n>] | Detect renames |
--find-copies[=<n>] | Detect copies |
--find-copies-harder | Find copies harder |
-B[<n>][/<m>], --break-rewrites[=<n>[/<m>]] | Break rewrite detection |
-M[<n>], --find-renames[=<n>] | Detect renames |
-C[<n>], --find-copies[=<n>] | Detect copies |
--irreversible-delete | Omit |
Output Control Options:
Section titled “Output Control Options:”| Option | Description |
|---|---|
--color[=<when>] | Color output control |
--no-color | Disable color output |
--word-diff[=<mode>] | Show word diff |
--word-diff-regex=<regex> | Word diff regex |
--color-words[=<regex>] | Color word diff |
-z | NUL line termination |
--quiet | Suppress all output |
--exit-code | Exit with diff status |
Advanced Options:
Section titled “Advanced Options:”| Option | Description |
|---|---|
--first-parent | Follow only first parent |
--merges | Show only merge commits |
--no-merges | Exclude merge commits |
--boundary | Show boundary commits |
--left-right | Mark left/right commits |
--cherry-mark | Mark equivalent commits |
--cherry-pick | Omit equivalent commits |
--walk-reflogs | Walk reflog entries |
--merge | Show commits touching conflicts |
--reverse | Show in reverse order |
-n <number>, --max-count=<number> | Limit number of commits |
--skip=<number> | Skip number of commits |
--since=<date> | Show commits after date |
--until=<date> | Show commits before date |
--author=<pattern> | Show commits by author |
--committer=<pattern> | Show commits by committer |
--grep=<pattern> | Show commits with message pattern |
--all-match | All grep patterns must match |
--invert-grep | Show commits not matching grep |
Parameters:
Section titled “Parameters:”| Parameter | Description |
|---|---|
<object> | Git object to show (commit, tag, tree, blob) |
Understanding Show Output:
Section titled “Understanding Show Output:”Commit Display Format:
Section titled “Commit Display Format:”Commit Information Display:commit <full-hash>Author: <name> <<email>>Date: <date>
<commit message>
diff --git a/<file> b/<file>index <old-hash>..<new-hash> <mode>--- a/<file>+++ b/<file>@@ -<start>,<count> +<start>,<count> @@ <context lines>-<removed line>+<added line> <context lines>Object Types:
Section titled “Object Types:”Git Objects git show Can Display:├── Commit: Full commit info + diff├── Tag: Tag info + tagged object├── Tree: Directory listing├── Blob: File contents└── Ref: Reference informationDiff Statistics:
Section titled “Diff Statistics:”Statistics Output Format:<file> | <additions> <deletions><file> | <additions> <deletions>...<n> files changed, <insertions> insertions(+), <deletions> deletions(-)Basic Show Operations:
Section titled “Basic Show Operations:”Showing Commits:
Section titled “Showing Commits:”# Show latest commitgit show
# Show specific commitgit show abc123
# Show commit with abbreviated infogit show --oneline HEAD
# Show commit without diffgit show --no-patch HEAD~2Showing Objects:
Section titled “Showing Objects:”# Show tag informationgit show v1.0
# Show tree objectgit show HEAD^{tree}
# Show blob (file) contentsgit show HEAD:README.md
# Show referencegit show HEADFormatting Output:
Section titled “Formatting Output:”# Custom formatgit show --format="Commit: %h by %an on %ad%n%s" HEAD
# Show only subjectgit show --format="%s" HEAD
# Show author infogit show --format="Author: %an <%ae>" HEADAdvanced Show Scenarios:
Section titled “Advanced Show Scenarios:”Detailed Diff Analysis:
Section titled “Detailed Diff Analysis:”# Show with statisticsgit show --stat HEAD
# Show numerical statisticsgit show --numstat HEAD
# Show only filenamesgit show --name-only HEAD
# Show filenames with statusgit show --name-status HEADWord-Level Differences:
Section titled “Word-Level Differences:”# Show word differencesgit show --word-diff HEAD
# Color word differencesgit show --color-words HEAD
# Custom word regexgit show --word-diff-regex="[A-Za-z]+" HEADContext Control:
Section titled “Context Control:”# Minimal contextgit show -U0 HEAD
# More contextgit show -U10 HEAD
# Function contextgit show --function-context HEADMultiple Objects:
Section titled “Multiple Objects:”# Show multiple commitsgit show HEAD HEAD~1 HEAD~2
# Show range of commitsgit show HEAD~5..HEAD
# Show merge commitsgit show --merges HEADConfiguration and Best Practices:
Section titled “Configuration and Best Practices:”Git Configuration for Show:
Section titled “Git Configuration for Show:”# Configure show behaviorgit config show.signature true # Show signature statusgit config show.notes true # Show commit notesgit config show.branch true # Show branch info
# Configure formattinggit config pretty.show "%h %s %d" # Custom show formatgit config format.pretty show # Use custom format
# Configure colorsgit config color.show.meta yellowgit config color.show.commit greengit config color.show.added greengit config color.show.removed redShow Best Practices:
Section titled “Show Best Practices:”# Use appropriate formatsgit show --oneline # Quick overviewgit show --stat # See what changedgit show -p # Full details
# Combine with other commandsgit show --name-only | xargs # Process changed filesgit show --format='%H' # Get commit hashgit show --no-patch --format='%s' # Get subject only
# Use in scriptscommit_info=$(git show --no-patch --format="%h %s %an")Safe Show Operations:
Section titled “Safe Show Operations:”# Check object exists before showingif git cat-file -e "$object" 2>/dev/null; then git show "$object"else echo "Object $object not found"fi
# Handle large diffsgit show --stat "$commit" | head -20 # Limit outputIntegration with Development Workflows:
Section titled “Integration with Development Workflows:”Code Review Preparation:
Section titled “Code Review Preparation:”#!/bin/bash# Prepare commit for code review
review_commit() { local commit="$1"
echo "=== Code Review: $commit ==="
# Basic commit info git show --no-patch --format="Commit: %h%nAuthor: %an <%ae>%nDate: %ad%n%n%s%n" "$commit"
# Statistics echo "Changes:" git show --stat "$commit"
# Generate patch file git show "$commit" > "review-$commit.patch"
# Check for large files large_files=$(git show --numstat "$commit" | awk '$1 > 1000000 {print $3}') if [ -n "$large_files" ]; then echo "Warning: Large files changed:" echo "$large_files" fi
echo "Review patch saved: review-$commit.patch"}
review_commit "abc123"Bug Investigation:
Section titled “Bug Investigation:”# Investigate bug introductioninvestigate_bug() { local bug_commit="$1"
echo "=== Bug Investigation ==="
# Show the problematic commit git show "$bug_commit"
# Find parent commits parents=$(git show --no-patch --format="%P" "$bug_commit")
echo "Parent commits:" for parent in $parents; do git show --oneline "$parent" done
# Show what changed compared to parent if [ -n "$parents" ]; then first_parent=$(echo "$parents" | cut -d' ' -f1) echo "Changes from parent:" git show "$first_parent..$bug_commit" --stat fi
# Check for related commits echo "Related commits in same area:" changed_files=$(git show --name-only "$bug_commit" | tail -n +2) for file in $changed_files; do git log --oneline -5 -- "$file" done | head -10}
investigate_bug "def456"Release Notes Generation:
Section titled “Release Notes Generation:”# Generate release notes from commitsgenerate_release_notes() { local since_tag="$1" local output_file="${2:-RELEASE_NOTES.md}"
echo "Generating release notes since $since_tag"
# Create release notes cat > "$output_file" << EOF# Release Notes
Changes since $since_tag
## Features$(git log --grep="^feat" --oneline --format="- %s" "$since_tag..HEAD")
## Bug Fixes$(git log --grep="^fix" --oneline --format="- %s" "$since_tag..HEAD")
## Other Changes$(git log --grep="^feat\|^fix" --invert-grep --oneline --format="- %s" "$since_tag..HEAD")
## Detailed ChangesEOF
# Add detailed commit information git log --oneline --no-merges "$since_tag..HEAD" >> "$output_file"
echo "Release notes generated: $output_file"}
generate_release_notes "v1.0.0"Troubleshooting Common Issues:
Section titled “Troubleshooting Common Issues:”Object Not Found:
Section titled “Object Not Found:”# Check object existsgit cat-file -t "$object" # Show object typegit cat-file -e "$object" # Check existence
# Find similar objectsgit show-ref | grep "$pattern"
# Check reflog for lost commitsgit reflog | grep "$object"Large Output Issues:
Section titled “Large Output Issues:”# Limit output for large commitsgit show --stat "$commit" | head -20
# Show only summarygit show --shortstat "$commit"
# Use external pagergit show "$commit" | lessEncoding Problems:
Section titled “Encoding Problems:”# Fix character encodinggit show --encoding=UTF-8 "$commit"
# Configure repository encodinggit config i18n.logOutputEncoding UTF-8
# Handle binary filesgit show --textconv "$commit"Performance Issues:
Section titled “Performance Issues:”# Speed up show operationsgit show --no-patch "$commit" # Skip diffgit show --name-only "$commit" # Just filenamesgit show --oneline "$commit" # Minimal info
# Use shallow clones for old commitsgit show --no-walk "$commit" # Single object onlyBinary File Issues:
Section titled “Binary File Issues:”# Handle binary filesgit show --binary "$commit"
# Use textconv filtersgit show --textconv "$commit"
# Configure textconv for specific filesecho "*.pdf diff=pdf" >> .gitattributesgit config diff.pdf.textconv 'pdftotext'Merge Commit Issues:
Section titled “Merge Commit Issues:”# Show merge commit detailsgit show "$merge_commit"
# Show only merge changesgit show --first-parent "$merge_commit"
# Compare merge parentsgit show "$merge_commit^1..$merge_commit^2"Tag Display Issues:
Section titled “Tag Display Issues:”# Show annotated taggit show v1.0
# Show lightweight taggit show --no-patch v1.0-light
# Show tag with signaturegit show --show-signature v1.0Path Resolution Issues:
Section titled “Path Resolution Issues:”# Show file at specific commitgit show "$commit:$path"
# Handle renamed filesgit show --follow "$commit" -- "$file"
# Show directory contentsgit show "$commit:$directory/"Real-World Usage Examples:
Section titled “Real-World Usage Examples:”Development Workflow Integration:
Section titled “Development Workflow Integration:”#!/bin/bash# Development workflow with show
dev_workflow_show() { echo "=== Development Workflow Show ==="
# Show recent commits echo "Recent commits:" git log --oneline -5
# Detailed view of current commit echo "" echo "Current commit details:" git show --no-patch --format="Commit: %h%nAuthor: %an%nDate: %ad%n%n%s"
# Show what changed echo "" echo "Changes in current commit:" git show --stat
# Check for large changes lines_changed=$(git show --shortstat | grep -o "[0-9]\+ insertions" | grep -o "[0-9]\+" || echo "0") if [ "$lines_changed" -gt 500 ]; then echo "⚠ Large commit detected ($lines_changed lines)" echo "Consider splitting into smaller commits" fi
# Show uncommitted changes if ! git diff --quiet; then echo "" echo "Uncommitted changes:" git diff --stat fi}
dev_workflow_showAutomated Code Review:
Section titled “Automated Code Review:”# Automated code review with showautomated_review() { local commit="$1"
echo "=== Automated Code Review: $commit ==="
# Basic validation author=$(git show --no-patch --format="%an" "$commit") subject=$(git show --no-patch --format="%s" "$commit")
echo "Author: $author" echo "Subject: $subject"
# Check commit message format if [[ ! "$subject" =~ ^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: ]]; then echo "⚠ Commit message doesn't follow conventional format" fi
# Check for large files large_files=$(git show --numstat "$commit" | awk '$1 > 1000000 || $2 > 1000000 {print $3}') if [ -n "$large_files" ]; then echo "⚠ Large files detected:" echo "$large_files" fi
# Check for sensitive data sensitive_found=$(git show "$commit" | grep -i "password\|secret\|key\|token" || true) if [ -n "$sensitive_found" ]; then echo "⚠ Potential sensitive data in commit" fi
# Check test coverage test_files=$(git show --name-only "$commit" | grep -E "\.(test|spec)\." | wc -l) source_files=$(git show --name-only "$commit" | grep -E "\.(js|py|java|cpp|c)" | wc -l)
if [ "$source_files" -gt 0 ] && [ "$test_files" -eq 0 ]; then echo "⚠ No test files changed with source code changes" fi
# Generate review summary cat > "review-$commit.md" << EOF# Code Review: $commit
## Summary- Author: $author- Subject: $subject- Files changed: $(git show --name-only "$commit" | wc -l)
## Changes$(git show --stat "$commit")
## Review Checklist- [ ] Code style and formatting- [ ] Test coverage- [ ] Documentation updates- [ ] Breaking changes identified- [ ] Security implications reviewed
## Detailed Changes$(git show "$commit")EOF
echo "Review summary saved: review-$commit.md"}
automated_review "abc123"Repository Analysis and Reporting:
Section titled “Repository Analysis and Reporting:”# Repository analysis with showrepo_analysis() { echo "=== Repository Analysis ==="
# Most active contributors echo "Top contributors by commits:" git shortlog -sn --no-merges | head -10
# Largest commits echo "" echo "Largest commits by lines changed:" git log --shortstat --no-merges | grep -E "commit [a-f0-9]+| [0-9]+ files? changed" | paste - - | awk ' { commit=$0 getline insertions=0 deletions=0 if (match($0, /([0-9]+) insertions/, arr)) insertions=arr[1] if (match($0, /([0-9]+) deletions/, arr)) deletions=arr[1] total=insertions+deletions print total, commit }' | sort -nr | head -10
# Most changed files echo "" echo "Most frequently changed files:" git log --name-only --no-merges | grep -v "^$" | sort | uniq -c | sort -nr | head -10
# Commit patterns echo "" echo "Commit message patterns:" git log --oneline --no-merges | cut -d' ' -f2- | sed 's/:.*//' | sort | uniq -c | sort -nr | head -10
# Recent activity echo "" echo "Recent activity (last 30 days):" git log --oneline --since="30 days ago" | wc -l echo " lines of development"
echo "Analysis complete"}
repo_analysisCI/CD Integration:
Section titled “CI/CD Integration:”# CI/CD pipeline with showci_validation() { echo "=== CI/CD Validation ==="
# Validate current commit current_commit=$(git rev-parse HEAD)
echo "Validating commit: $current_commit"
# Check commit signature if required if git config --bool commit.gpgsign; then if ! git show --show-signature "$current_commit" | grep -q "gpg: Good signature"; then echo "ERROR: Commit not properly signed" exit 1 fi echo "✓ Commit signature verified" fi
# Check for merge commits in feature branches current_branch=$(git branch --show-current) if [[ "$current_branch" == feature/* ]]; then merge_commits=$(git log --oneline --merges "$current_commit" | wc -l) if [ "$merge_commits" -gt 0 ]; then echo "⚠ Merge commits found in feature branch" fi fi
# Validate commit message format subject=$(git show --no-patch --format="%s" "$current_commit") if [[ ! "$subject" =~ ^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: ]]; then echo "⚠ Commit message doesn't follow conventional format" fi
# Check for large files large_files=$(git show --numstat "$current_commit" | awk '$1 > 5000000 || $2 > 5000000 {print $3}') if [ -n "$large_files" ]; then echo "⚠ Large files detected in commit:" echo "$large_files" fi
# Generate deployment notes cat > "deploy-notes.txt" << EOFDeployment Notes for $current_commit
Commit: $(git show --no-patch --format="%h %s" "$current_commit")Author: $(git show --no-patch --format="%an" "$current_commit")Date: $(git show --no-patch --format="%ad" "$current_commit")
Files Changed:$(git show --name-only "$current_commit" | tail -n +2)
Changes Summary:$(git show --shortstat "$current_commit")EOF
echo "✓ CI validation passed" echo "Deployment notes saved: deploy-notes.txt"}
ci_validationSecurity Auditing:
Section titled “Security Auditing:”# Security audit with showsecurity_audit() { local since="${1:-1 month ago}"
echo "=== Security Audit ===" echo "Analyzing commits since: $since"
# Check for sensitive data patterns echo "Checking for potential sensitive data..." sensitive_commits=$(git log --oneline --since="$since" | while read -r line; do commit=$(echo "$line" | cut -d' ' -f1) if git show "$commit" | grep -q -i "password\|secret\|key\|token\|credential"; then echo "$line" fi done)
if [ -n "$sensitive_commits" ]; then echo "⚠ Potential sensitive data found in commits:" echo "$sensitive_commits" else echo "✓ No sensitive data patterns detected" fi
# Check for large binary files echo "" echo "Checking for large files..." large_commits=$(git log --oneline --since="$since" | while read -r line; do commit=$(echo "$line" | cut -d' ' -f1) large_files=$(git show --numstat "$commit" | awk '$1 > 10000000 || $2 > 10000000 {print $3}') if [ -n "$large_files" ]; then echo "$line (large files: $large_files)" fi done)
if [ -n "$large_commits" ]; then echo "⚠ Large files found in commits:" echo "$large_commits" else echo "✓ No excessively large files detected" fi
# Check for unsigned commits if required if git config --bool commit.gpgsign; then echo "" echo "Checking commit signatures..." unsigned_commits=$(git log --oneline --since="$since" | while read -r line; do commit=$(echo "$line" | cut -d' ' -f1) if ! git show --show-signature "$commit" 2>/dev/null | grep -q "gpg: Good signature"; then echo "$line" fi done)
if [ -n "$unsigned_commits" ]; then echo "⚠ Unsigned commits found:" echo "$unsigned_commits" else echo "✓ All commits are properly signed" fi fi
echo "" echo "Security audit complete"}
security_auditWhat’s the difference between git show and git log?
Section titled “What’s the difference between git show and git log?”git show displays detailed information about a single object, while git log shows history of multiple commits. Use show for deep inspection, log for browsing history.
How do I see what changed in a specific commit?
Section titled “How do I see what changed in a specific commit?”Use git show
Can git show display file contents from a specific commit?
Section titled “Can git show display file contents from a specific commit?”Yes, use git show
How do I see only the commit message without the diff?
Section titled “How do I see only the commit message without the diff?”Use git show —no-patch
What’s the difference between git show HEAD and git log -p -1?
Section titled “What’s the difference between git show HEAD and git log -p -1?”They show the same information - the latest commit with full diff. git show is more concise.
Can git show display information about tags?
Section titled “Can git show display information about tags?”Yes, git show
How do I see statistics for a commit’s changes?
Section titled “How do I see statistics for a commit’s changes?”Use git show —stat
Can git show work with merge commits?
Section titled “Can git show work with merge commits?”Yes, it shows merge commit information and diffs. Use —first-parent to focus on the main branch changes.
How do I see word-level differences in a commit?
Section titled “How do I see word-level differences in a commit?”Use git show —word-diff
What’s the —name-only option for?
Section titled “What’s the —name-only option for?”—name-only shows only the names of files that were changed in the commit, without the diff content.
Can git show display binary file changes?
Section titled “Can git show display binary file changes?”It shows that binary files changed but doesn’t display the actual binary diff. Use —binary to include binary diff data.
How do I see the author and committer information?
Section titled “How do I see the author and committer information?”Use git show —no-patch —format=“Author: %an <%ae>%nCommitter: %cn <%ce>”
Can git show work with tree objects?
Section titled “Can git show work with tree objects?”Yes, git show
How do I see the raw diff format?
Section titled “How do I see the raw diff format?”Use git show —raw
What’s —irreversible-delete for?
Section titled “What’s —irreversible-delete for?”It omits the destination (
Can git show display notes attached to commits?
Section titled “Can git show display notes attached to commits?”Yes, use git show —notes
How do I see the signature status of a commit?
Section titled “How do I see the signature status of a commit?”Use git show —show-signature
Can git show work with ranges?
Section titled “Can git show work with ranges?”Yes, git show
How do I limit the context in diff output?
Section titled “How do I limit the context in diff output?”Use git show -U
What’s the —boundary option for?
Section titled “What’s the —boundary option for?”When used with ranges, —boundary shows the boundary commits that limit the range.
Can git show display the commit graph?
Section titled “Can git show display the commit graph?”Use git show —graph
Applications of the git show command
Section titled “Applications of the git show command”- Code Review: Detailed inspection of individual commits and their changes
- Bug Investigation: Analyzing specific commits that introduced or fixed issues
- Release Validation: Verifying the contents and changes in release commits
- Security Auditing: Checking commits for sensitive data or security issues
- Repository Analysis: Understanding what changed in specific points in history
- Patch Generation: Creating patches from individual commits
- Documentation: Generating detailed change documentation
- Quality Assurance: Validating commit contents and adherence to standards