List files modified for particular git commit
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
To list the files modified by a specific Git commit, the most common commands are git show --name-only and git diff-tree --name-only. Both can answer the question, but they emphasize slightly different output styles and are useful in different contexts.
The Quickest Human-Friendly Command
If you want an easy command for everyday terminal use, git show is a good starting point.
Example:
This prints only the paths touched by that commit, without the full patch body.
The --format= part suppresses the commit header. Without it, git show also prints commit metadata.
A More Script-Friendly Command
For automation and scripting, git diff-tree is often a cleaner fit:
Example:
This is especially useful when you want a stable command focused on tree differences rather than commit display formatting.
Include Change Status When Needed
Sometimes file names alone are not enough. You may also want to know whether each file was added, modified, deleted, renamed, or copied.
Use:
or:
Typical output might look like:
That extra status information is often more useful than names alone in code review or deployment tooling.
Compare a Commit Against Its Parent
A commit’s changed files are basically the difference between that commit and its parent.
That means this also works:
For example:
This is conceptually simple, but it depends on the commit having a single parent. That becomes more complicated for merge commits, which is why git show or git diff-tree is often easier in general.
Special Case: Merge Commits
Merge commits are important because they may have more than one parent. If you inspect them casually, the meaning of “files modified by the commit” can vary depending on whether you compare against the first parent or inspect combined changes.
For many everyday workflows, the first-parent view is what people want:
But if you are auditing merges carefully, be explicit about which parent relationship you care about.
This matters in release tooling, changelog generation, and branch integration debugging.
Useful Variants
Here are a few related commands worth knowing:
Only names:
Names plus status:
Names only from the last commit:
One path per line from a commit tree diff:
These cover most practical use cases.
Choosing Between git show and git diff-tree
Use git show when:
- you are exploring interactively
- you already think in commits
- you may want to expand into patch inspection later
Use git diff-tree when:
- you want leaner script-oriented output
- you are writing tooling
- you want to stay closer to tree-diff semantics
Both are valid. The best choice depends on whether the task is human inspection or automation.
Common Pitfalls
The most common pitfall is forgetting --format= with git show and then getting commit metadata mixed into output that was supposed to be machine-readable.
Another mistake is using <commit>^ <commit> without thinking about merge commits, where the parent relationship is more complex.
A third issue is listing only names when status information is actually needed to understand what changed.
Finally, some developers use very complicated Git commands when a simple git show --name-only --format= would answer the question immediately.
Summary
- Use
git show --name-only --format= <commit>for a simple human-friendly list of files changed in a commit. - Use
git diff-tree --no-commit-id --name-only -r <commit>for script-friendly output. - Add
--name-statuswhen you also need added, modified, or deleted status codes. - Be careful with merge commits because parent comparisons become less obvious.
- Pick the command based on whether the task is interactive inspection or automation.

