git show

Show a commit summary, limit it with --, print a blob, and a missing-path exit, checked on Git 2.39.5.

git show inspects one Git object. For a commit, the default is the log message plus a patch. --stat and --name-only shrink that to a file summary. A path after -- limits the patch to those paths.

Examples were checked on Git 2.39.5 in isolated temporary repositories. For annotated versus lightweight tags, see the git tag page; this page shows how path limits and blob paths behave for a commit.

Examples were checked against Git 2.39.5. See the official documentation for the complete command.

Git command catalog → · Git tutorial overview →

Commit summaries, path limits, and blobs

The example's HEAD commit adds app.txt. git show --stat --oneline and --name-only report that file. git show HEAD -- app.txt keeps the summary, but git show HEAD -- README.md prints nothing and still exits 0, because that commit did not change README.md. An empty show is not proof of an error.

git show HEAD:app.txt prints the blob content stored in that commit. git show HEAD:missing.txt exits 128 and writes a fatal error. The example captures that error with 2>&1. Do not invent a different generic error status for a missing path unless you have measured it.

git show, git show --, git show <rev>:<path>

git show [<options>] [<object>] [--] [<path>...]
git show <rev>:<path>

Show a commit summary or a blob, optionally limited to a path, and fail when a colon path does not exist.

ParameterDescription
<object>A commit, tag, tree, or blob. The default is HEAD.
-- <path>...Limit the commit patch or name list to those paths. A path that did not change in that commit can yield empty output and still exit 0.
<rev>:<path>The blob at that path in the given revision, without a patch header.

Returns: A formatted object on standard output. For a missing <rev>:<path>, Git prints a fatal error and does not print the blob.

Exit status

  • 0 — The object was shown, or the path limiter matched no changes in that commit. Measured for both the app.txt path and the unchanged README.md path on Git 2.39.5.
  • 128 — fatal: path 'missing.txt' does not exist in 'HEAD'. Measured on Git 2.39.5. The message is on standard error.
  • The %h%x20%s pretty format is a short SHA, a space, and the subject. It keeps the output stable.
bash
git init -b main >/dev/null
git config user.name "Practice Author"
git config user.email "[email protected]"
git config commit.gpgsign false
git config color.ui false
mkdir -p .disabled-hooks
git config core.hooksPath ".disabled-hooks"
printf 'readme-a\n' > README.md
git add README.md
git commit -m "Add README" >/dev/null
printf 'app-a\n' > app.txt
git add app.txt
GIT_AUTHOR_DATE='2024-01-15T13:00:00+0000' GIT_COMMITTER_DATE='2024-01-15T13:00:00+0000' git commit -m "Add app" >/dev/null
echo "stat"
git show --stat --oneline HEAD
echo "name-only"
git show --name-only --pretty=format:%h%x20%s HEAD
echo
echo "path-app"
git show --name-only --pretty=format:%h%x20%s HEAD -- app.txt
echo
echo "path-readme"
out=$(git show --name-only --pretty=format:%h%x20%s HEAD -- README.md)
st=$?
if [ -z "$out" ]; then echo "(empty)"; else printf '%s\n' "$out"; fi
echo "path-unchanged-exit=$st"
echo "missing-path"
git show HEAD:missing.txt 2>&1
echo "missing-exit=$?"
echo "blob"
git show HEAD:app.txt
echo "blob-exit=$?"

Expected output

stat
e25862f Add app
 app.txt | 1 +
 1 file changed, 1 insertion(+)
name-only
e25862f Add app
app.txt

path-app
e25862f Add app
app.txt

path-readme
(empty)
path-unchanged-exit=0
missing-path
fatal: path 'missing.txt' does not exist in 'HEAD'
missing-exit=128
blob
app-a
blob-exit=0

Related: git log, git tag, git commit

Official documentation →