Git Show: read one commit
git show prints one commit: its message and its changes. --name-only lists only the changed file names. Only a plain commit was shown. --format=%s replaces the message header with the subject line, and -s hides the diff.
Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.
TE-69-A: show with --format=%s and --name-only prints the subject and the changed file
Setup for this run, inside a throwaway directory (mktemp -d):
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm first
printf 'b\n' > g.txt; git add g.txt; git commit -qm 'add g'Command:
git show --format=%s --name-only HEADRecorded output:
add g
g.txtExit status: 0. The output matches the expected text written before the run.
TE-69-B: show with --format=%s and -s prints only the subject line
Setup for this run, inside a throwaway directory (mktemp -d):
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm first
printf 'b\n' > g.txt; git add g.txt; git commit -qm 'add g'Command:
git show --format=%s -s HEADRecorded output:
add gExit status: 0. The output matches the expected text written before the run.
TE-69-C: expected non-zero exit: git show with a name that is not a commit stops with a fatal error
Setup for this run, inside a throwaway directory (mktemp -d):
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm baseCommand:
git show nosuchrefRecorded output: none, standard output was empty.
Standard error from the same run:
fatal: ambiguous argument 'nosuchref': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'Exit status: 128. This status and the output match what was written before the run.
Reading the recorded output
In TE-69-A the first line, add g, is the subject of the newest commit, and the second line, g.txt, is the name of the file that commit changed. By the setup, that commit added g.txt. No diff text was printed. In TE-69-B the same command with -s in place of --name-only printed only the subject line, add g, and no file name.
TE-69-C: git show nosuchref exited with status 128 and printed fatal: ambiguous argument 'nosuchref': unknown revision or path not in the working tree. to standard error.
Limits
Only a plain commit was shown. Merge commits, tags and commit:path forms were not tested. Not tested on this page: -q (suppress diff output), --source (show the source), --use-mailmap and its alias --mailmap (use the mail map file). The names and descriptions come from the usage text printed by git show -h in git 2.34.1. No git show command here used them. The usage text also shows that git show takes one or more objects; showing several objects in one call was not run.
Source
- https://git-scm.com/docs/git-show
- https://git-scm.com/docs/pretty-formats
- https://git-scm.com/docs/diff-options
Evidence table
| Test | What it checks | Exit | Verdict | Log sha256 (first 12) | |---|---|---|---|---| | TE-69-A | show with --format=%s and --name-only prints the subject and the changed file | 0 | PASS | a9919a4ae6b7 | | TE-69-B | show with --format=%s and -s prints only the subject line | 0 | PASS | 564cf12116b5 | | TE-69-C | expected non-zero exit: git show with a name that is not a commit stops with a fatal error | 128 | PASS | 3947c76d22b5 |
Recorded on: bash 5.1.16(1)-release; git version 2.34.1; Python 3.10.12. Locale C.UTF-8, TZ=UTC. Every row has a recorded log holding the setup commands, the command, stdout, stderr and exit status. The first 12 characters of the log's sha256 are in the table.
All full guides: All guides