Skip to content

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.

Terminal window
git show [<options>] [<object>...]
OptionDescription
-p, --patchGenerate patch (default for commits)
-s, --no-patchSuppress diff output
--format=<format>Pretty-print with custom format
--onelineShow oneline format
--name-onlyShow only changed filenames
--name-statusShow filenames with status
--statShow diff statistics
--numstatMachine-readable diff statistics
--shortstatSummary of total changes
OptionDescription
--abbrev-commitShow abbreviated commit hashes
--no-abbrev-commitShow full commit hashes
--onelineAbbreviated commit + subject
--encoding=<encoding>Re-encode commit messages
--expand-tabs[=<n>]Expand tabs in output
--no-expand-tabsDon’t expand tabs
--notes[=<ref>]Show notes
--no-notesDon’t show notes
--show-signatureShow signature status
OptionDescription
-U<n>, --unified=<n>Lines of context
--rawGenerate raw diff format
--patch-with-rawOutput both patch and raw
--patch-with-statOutput patch and stat
--no-renamesDon’t detect renames
--find-renames[=<n>]Detect renames
--find-copies[=<n>]Detect copies
--find-copies-harderFind 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-deleteOmit for deletions
OptionDescription
--color[=<when>]Color output control
--no-colorDisable color output
--word-diff[=<mode>]Show word diff
--word-diff-regex=<regex>Word diff regex
--color-words[=<regex>]Color word diff
-zNUL line termination
--quietSuppress all output
--exit-codeExit with diff status
OptionDescription
--first-parentFollow only first parent
--mergesShow only merge commits
--no-mergesExclude merge commits
--boundaryShow boundary commits
--left-rightMark left/right commits
--cherry-markMark equivalent commits
--cherry-pickOmit equivalent commits
--walk-reflogsWalk reflog entries
--mergeShow commits touching conflicts
--reverseShow 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-matchAll grep patterns must match
--invert-grepShow commits not matching grep
ParameterDescription
<object>Git object to show (commit, tag, tree, blob)
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>
Git Objects git show Can Display:
├── Commit: Full commit info + diff
├── Tag: Tag info + tagged object
├── Tree: Directory listing
├── Blob: File contents
└── Ref: Reference information
Statistics Output Format:
<file> | <additions> <deletions>
<file> | <additions> <deletions>
...
<n> files changed, <insertions> insertions(+), <deletions> deletions(-)
Terminal window
# Show latest commit
git show
# Show specific commit
git show abc123
# Show commit with abbreviated info
git show --oneline HEAD
# Show commit without diff
git show --no-patch HEAD~2
Terminal window
# Show tag information
git show v1.0
# Show tree object
git show HEAD^{tree}
# Show blob (file) contents
git show HEAD:README.md
# Show reference
git show HEAD
Terminal window
# Custom format
git show --format="Commit: %h by %an on %ad%n%s" HEAD
# Show only subject
git show --format="%s" HEAD
# Show author info
git show --format="Author: %an <%ae>" HEAD
Terminal window
# Show with statistics
git show --stat HEAD
# Show numerical statistics
git show --numstat HEAD
# Show only filenames
git show --name-only HEAD
# Show filenames with status
git show --name-status HEAD
Terminal window
# Show word differences
git show --word-diff HEAD
# Color word differences
git show --color-words HEAD
# Custom word regex
git show --word-diff-regex="[A-Za-z]+" HEAD
Terminal window
# Minimal context
git show -U0 HEAD
# More context
git show -U10 HEAD
# Function context
git show --function-context HEAD
Terminal window
# Show multiple commits
git show HEAD HEAD~1 HEAD~2
# Show range of commits
git show HEAD~5..HEAD
# Show merge commits
git show --merges HEAD
Terminal window
# Configure show behavior
git config show.signature true # Show signature status
git config show.notes true # Show commit notes
git config show.branch true # Show branch info
# Configure formatting
git config pretty.show "%h %s %d" # Custom show format
git config format.pretty show # Use custom format
# Configure colors
git config color.show.meta yellow
git config color.show.commit green
git config color.show.added green
git config color.show.removed red
Terminal window
# Use appropriate formats
git show --oneline # Quick overview
git show --stat # See what changed
git show -p # Full details
# Combine with other commands
git show --name-only | xargs # Process changed files
git show --format='%H' # Get commit hash
git show --no-patch --format='%s' # Get subject only
# Use in scripts
commit_info=$(git show --no-patch --format="%h %s %an")
Terminal window
# Check object exists before showing
if git cat-file -e "$object" 2>/dev/null; then
git show "$object"
else
echo "Object $object not found"
fi
# Handle large diffs
git show --stat "$commit" | head -20 # Limit output
#!/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"
Terminal window
# Investigate bug introduction
investigate_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"
Terminal window
# Generate release notes from commits
generate_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 Changes
EOF
# 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"
Terminal window
# Check object exists
git cat-file -t "$object" # Show object type
git cat-file -e "$object" # Check existence
# Find similar objects
git show-ref | grep "$pattern"
# Check reflog for lost commits
git reflog | grep "$object"
Terminal window
# Limit output for large commits
git show --stat "$commit" | head -20
# Show only summary
git show --shortstat "$commit"
# Use external pager
git show "$commit" | less
Terminal window
# Fix character encoding
git show --encoding=UTF-8 "$commit"
# Configure repository encoding
git config i18n.logOutputEncoding UTF-8
# Handle binary files
git show --textconv "$commit"
Terminal window
# Speed up show operations
git show --no-patch "$commit" # Skip diff
git show --name-only "$commit" # Just filenames
git show --oneline "$commit" # Minimal info
# Use shallow clones for old commits
git show --no-walk "$commit" # Single object only
Terminal window
# Handle binary files
git show --binary "$commit"
# Use textconv filters
git show --textconv "$commit"
# Configure textconv for specific files
echo "*.pdf diff=pdf" >> .gitattributes
git config diff.pdf.textconv 'pdftotext'
Terminal window
# Show merge commit details
git show "$merge_commit"
# Show only merge changes
git show --first-parent "$merge_commit"
# Compare merge parents
git show "$merge_commit^1..$merge_commit^2"
Terminal window
# Show annotated tag
git show v1.0
# Show lightweight tag
git show --no-patch v1.0-light
# Show tag with signature
git show --show-signature v1.0
Terminal window
# Show file at specific commit
git show "$commit:$path"
# Handle renamed files
git show --follow "$commit" -- "$file"
# Show directory contents
git show "$commit:$directory/"
#!/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_show
Terminal window
# Automated code review with show
automated_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"
Terminal window
# Repository analysis with show
repo_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_analysis
Terminal window
# CI/CD pipeline with show
ci_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" << EOF
Deployment 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_validation
Terminal window
# Security audit with show
security_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_audit

What’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 to see the full diff, or git show —stat for a summary of changes.

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 : to display the contents of a file at that commit.

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 or git show —format=“%B” .

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 displays tag information, annotation, and the tagged commit.

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 for file-by-file statistics, or git show —shortstat for summary.

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 to see changes at the word level instead of line level.

—name-only shows only the names of files that were changed in the commit, without the diff content.

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>” .

Yes, git show displays the directory listing for that tree object.

Use git show —raw for the low-level diff format that shows exact object changes.

It omits the destination () part for deleted files in patches, making them suitable for irreversible operations.

Can git show display notes attached to commits?

Section titled “Can git show display notes attached to commits?”

Yes, use git show —notes to display any notes attached to the commit.

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 to verify and display GPG signature information.

Yes, git show .. shows commits in that range, similar to git log.

How do I limit the context in diff output?

Section titled “How do I limit the context in diff output?”

Use git show -U to specify the number of context lines around changes.

When used with ranges, —boundary shows the boundary commits that limit the range.

Use git show —graph to include ASCII graph visualization of commit relationships.

  1. Code Review: Detailed inspection of individual commits and their changes
  2. Bug Investigation: Analyzing specific commits that introduced or fixed issues
  3. Release Validation: Verifying the contents and changes in release commits
  4. Security Auditing: Checking commits for sensitive data or security issues
  5. Repository Analysis: Understanding what changed in specific points in history
  6. Patch Generation: Creating patches from individual commits
  7. Documentation: Generating detailed change documentation
  8. Quality Assurance: Validating commit contents and adherence to standards