To list all the files in a Git commit, run git show --name-only <commit-hash>, which displays the commit metadata followed by the names of every file that was added, modified, or deleted. If you need just the filenames without any extra output, git diff-tree --no-commit-id --name-only -r <commit-hash> gives a clean, scriptable list.
Using git show
git show is the primary command to list files in a commit, displaying information about a Git object such as a commit, tree, or blob. Run it with the --name-only flag and the commit hash you want to inspect:
git show --name-only <commit-hash>
This prints the commit message along with the affected filenames. If you want the file list without the commit message cluttering the output, add --pretty="":
git show --pretty="" --name-only <commit-hash>
To see not just which files changed but how they changed — added, modified, or deleted — swap in --name-status:
git show --name-status <commit-hash>
Using git diff-tree
git diff-tree is built specifically for this kind of output and skips the commit metadata entirely, making it a better fit for scripts or automated tooling. Running git diff-tree –no-commit-id –name-only -r on a commit hash returns a list of all files changed by that commit.
git diff-tree --no-commit-id --name-only -r <commit-hash>
The -r flag makes the listing recursive so it picks up files in subdirectories, and --no-commit-id strips the commit hash from the output, leaving just filenames — one per line.
Using git log
If you’re inspecting a range of commits rather than just one, git log handles that better than git show or git diff-tree, since it’s better suited for showing more than a single commit at once. Pair it with --raw for a per-commit file listing across your history:
git log --raw
For a more focused view of a single commit’s file list without merge commits mixed in, git whatchanged works as a simpler alternative, and adding --patch to git log will also show the actual line-by-line diff for each file if you need that level of detail.
Choosing the Right Command
Use git show --name-only for a quick, one-off look at a single commit — it’s the most direct option when working interactively. Reach for git diff-tree --no-commit-id --name-only -r when you need clean output for a script, since it avoids parsing out extra metadata. git log --raw or git log --patch make more sense when you’re reviewing several commits at once or need to see the actual content changes alongside the file list.
Join The Discussion
What’s your go-to command for inspecting commit contents, and have you found any particular flag combinations that make code review or debugging faster?