Handcrafting Codes← Index

Engineering

Listing the files in a commit, and the question you're asking

"List the files in a commit" sounds like one question.

Jul 02, 2026 / 2 min read / By the author

COVER IMAGE — 16:9

"List the files in a commit" sounds like one question. It's two, and they have different answers. Are you asking which files that commit changed, or which files existed in the repo at that point? Git has a command for each, and reaching for the wrong one gives you a confidently wrong answer.

Files the commit changed

This is usually what you want: the files a specific commit added, modified, or deleted, and nothing else.

git diff-tree --no-commit-id --name-only -r <commit_hash>

The flags matter. --no-commit-id suppresses the hash from the output, --name-only drops the diff body, and -r recurses into subdirectories so you get full paths rather than just top-level folders. The result is a clean list:

Manual Configurations/SFOPS/SFOPS-2418.md
Manual Configurations/post-deploy.md

There's a shorter way to ask the same thing:

git show --pretty="format:" --name-only <commit_hash>

The empty format: strips the commit header so you're left with just the changed filenames. Same answer, fewer flags to remember.

Files that existed at that commit

Different question entirely. This lists every file tracked in the repo as of that commit, including the thousands that commit never touched, because they were committed by something earlier and simply carried forward.

git ls-tree --name-only -r <commit_hash>

ls-tree reads the tree object, which is git's snapshot of the entire project at that point. If you run this expecting "what did this commit do" you'll get a wall of unrelated files and conclude the commit was enormous. It wasn't. You asked the snapshot question instead of the diff question. Use ls-tree when you want the full state, like checking whether a file even existed yet at a given point in history.

Changed files plus their stats

When you want the names and a sense of how much moved:

git show --stat --oneline <commit_hash>

This gives you the subject line, the changed files, and the insertion and deletion counts:

fed7cc421 SFOPS-2418: Removing last change from Case.settings-meta.xml
 force-app/main/default/settings/Case.settings-meta.xml | 13 -------------
 1 file changed, 13 deletions(-)

The +/- histogram is a quick gut check on whether a commit is a one-line tweak or something that rewrote half a file, before you bother opening the full diff.

The distinction underneath all of this is the one worth keeping: a commit is both a change and a snapshot. diff-tree and show --name-only answer the change question. ls-tree answers the snapshot question. Pick based on which one you need, and the output stops being surprising.