Sub topic 7
Seeing the changes in each commit: show, log -p, log --stat
This chapter assumes you can run git log and read a unified diff, as covered in earlier chapters. By default, git log lists commit metadata only. To see what each commit changed, you add a flag to log or use git show.
The working model
Every commit stores a snapshot of the project, not a list of changes. Git computes the change for a commit by comparing its snapshot with its parent's snapshot. The commands in this chapter run that comparison for you and print the result.
| Command | What it prints |
|---|---|
| `git show <commit>` | Metadata and the patch for one commit |
| `git log -p` | Metadata and the patch for every commit in the list |
| `git log --stat` | Metadata and a per-file line count for every commit |
| `git show --name-status` | Metadata and a status letter for each changed file |
Inspecting one commit with git show
git show with no argument displays the commit at HEAD. Give it any commit name to see another one.
git show
git show 8c4d9e2
git show HEAD~2The output has the commit header (hash, author, date, message) followed by a unified diff against the parent. To see only the file names and status, add --name-status:
git show --name-status HEADEach line starts with a letter: A for added, M for modified, D for deleted, and R followed by a similarity score for renamed. Add --oneline or --pretty=format:... to shrink the header, and --stat for line counts instead of a patch.
Patches across history with log -p
Adding -p (or --patch) makes git log print the diff under each commit. Combine it with a count and a path to keep the output small.
git log -p -n 2 -- src/config.cThis shows the two most recent commits that touched src/config.c. Without the path after --, each patch would include every file in the commit. With the path, Git also hides changes to other files in those commits.
Overview with log --stat
A patch can be long. --stat condenses each commit to a list of files and how many lines changed in each.
git log --stat -n 3A typical entry looks like this:
commit 8c4d9e2a1b7f...
Author: Alice <[email protected]>
Date: Tue Nov 3 10:12:44 2026 +0000
Validate config on load
app.py | 3 ++-
tests/test.py | 12 ++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)The + and - characters after each count show the proportion of additions to deletions. Git scales the bars to fit the terminal width for large changes.
Common errors
- Merge commits show no patch. By default,
git log -pprints nothing for a merge, andgit showprints a combined diff that lists only files changed relative to both parents. To see the merge against its first parent, usegit log -p -m --first-parentorgit show -m. - Forgetting
--. Without--, Git may read a path as a revision name if the two are ambiguous. Put paths after--. - Patch output for the root commit. The first commit has no parent, so
git showdisplays all its files as added. - Huge output. Pipe to a pager or add
-n. Git uses a pager automatically on a terminal.
Exercise
You want to read the patch for only src/config.c from the commit 8c4d9e2, and not the other files in that commit. Which command do you run?
Show answer
git show 8c4d9e2 -- src/config.c. The path after -- limits the patch to that file.
Exercise
You need a quick list of which files each of the last five commits changed and how many lines, without reading any patches. Which command do you run?
Show answer
git log --stat -n 5