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.
| Parameter | Description |
|---|---|
<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.
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