git show

Inspection & Comparison

Show a commit, a tag or a file at a given version


The 'git show' command displays one object. For a commit it prints the author, date and message followed by the diff that commit introduced. For an annotated tag it shows the tag message and then the commit. With <commit>:<path> it prints a file exactly as it was in that commit.

Synopsis

git show [<options>] [<object>...]
[ ] optional| or<arg> placeholder... repeatable--flag option

Options

Click any option to expand

Beginner (2)

Show a summary of changed files instead of the full diff.

RecommendedQuick size check of a commit before reading it

Example

git show --stat

Print the header as one line: short hash and subject.

When neededCompact header when you only care about the diff

Example

git show --oneline

Choosing the Right Option

show vs log vs diff

Three ways to look at history

CommandShows
git logA list of commits
git show <commit>One commit and its changes
git diff A BThe difference between any two versions

Examples

Last commit

git show

Shows HEAD with its diff.


Any commit

git show a1b2c3d

Shows that commit.


A file in an old commit

git show HEAD~2:app.js

Prints app.js as it was two commits ago.


Summary only

git show --stat

Files changed instead of the full diff.

Workflow Examples

1
git log --oneline

Find it

2
git show --stat a1b2c3d

Which files it touched

3
git show a1b2c3d

The full change

Troubleshooting

fatal: path 'x' does not exist in 'HEAD~1'

Cause: The file did not exist in that commit, or the path is wrong

Use the path from the repository root; check with git show --stat

A merge commit shows no diff

Cause: Merges show a combined diff only for conflicting lines

Use git show -m or git diff <merge>^1 <merge>

Tips & Pitfalls

Best Practices

  • ✓Use --stat first on large commits.
  • ✓Use commit:path to read an old version without changing your files.

Common Mistakes

  • ✗Writing git show HEAD~1 app.js (a filter) when you meant HEAD~1:app.js (the file content).
  • ✗Using a path relative to your folder without ./ in commit:path — paths are from the repository root.

FAQ

A:

git show <commit>.

A:

To read it: git show <commit>:<path>. To restore it: git restore --source=<commit> <path>.