Philip Fourie Philip Fourie - 1 year ago 87
Git Question

How to list all the files in a commit?

I am looking for a simple

command that provides a nicely formatted list of all files that were part of the commit given by a hash (SHA1), with no extraneous information.

I have tried:

git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d

Although it lists the files, it also includes unwanted diff information for each.

Is there another
command that will provide just the list I want, so that I can avoid parsing it from the
git show

Answer Source

Preferred Way (because it's a plumbing command; meant to be programmatic):

$ git diff-tree --no-commit-id --name-only -r bd61ad98

Another Way (less preferred for scripts, because it's a porcelain command; meant to be user-facing)

$ git show --pretty="" --name-only bd61ad98    

  • The --no-commit-id suppresses the commit ID output.
  • The --pretty argument specifies an empty format string to avoid the cruft at the beginning.
  • The --name-only argument shows only the file names that were affected (Thanks Hank).
  • The -r argument is to recurse into sub-trees
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download