Git Reference ยท Inspecting History
git show command
Reference for git show: print a commit with its diff, view annotated tags, list trees, print file contents at any revision, and control the format of merge diffs.
git show prints one or more Git objects in a form people can read. Give it a commit and it shows the message and the patch that commit introduced; give it a tag and it shows the tag message followed by the tagged object; give it a tree and it lists the entries; give it a blob and it prints the file as it was stored.
With no argument it shows HEAD. Because it accepts any revision syntax, git show HEAD~2:src/app.js is also the quickest way to read an old version of a file without checking it out. For ranges and history browsing use git log; git show is for looking at specific objects.
git show git show <commit> git show <rev>:<path>
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
git show [<options>] [<object>...] [[--] <path>...]
| Name | Description |
|---|---|
<object> |
A commit, tag, tree or blob. Several objects are shown one after another. Defaults to HEAD. |
<rev>:<path> |
The blob or tree at that path in that revision. |
:<path> |
The staged version of a file from the index. |
-- <path>... |
Limit the patch of a commit to these paths. |
-s, --no-patch |
Suppress the diff and show only the header and message. |
--format=<fmt>, --pretty=<fmt> |
Choose the commit layout (see git log --pretty). --format= with an empty value prints nothing but the diff. |
--stat, --name-only, --name-status, --word-diff |
Summaries and diff styles; all diff options are accepted. |
--cc, -c, -m |
Merge diff styles: combined, dense-combined, or separate against each parent. |
--first-parent |
With -m, diff only against the first parent. |
Returns: exit status 0; 128 with fatal: when an object or path does not exist.
Usage notes
- Object types decide the output. Commit: header, message and patch. Annotated tag: tagger, date and message, then the tagged object. Tree:
tree <name>, a blank line, then the entry names (directories end with/). Blob: raw bytes. - Merges show a combined diff by default (
--cc): only hunks that differ from all parents are shown, with two columns of+/-marks. Use-mto see each parent's diff separately. - Root commits are shown as if every file was added.
- Binary files are printed raw for a blob, which may mess up a terminal; for a commit they appear as
Binary files differ. git show :pathprints the staged version, useful to check what is about to be committed.:1:path,:2:pathand:3:pathname the conflict stages (see Revision syntax).- For scripts, prefer
git cat-fileto get exact object contents, and--formatwith-sto extract commit fields.
Related
git log,git diff,git cat-file,git ls-tree- Lessons: Log and show, Revisions