megclaypool of Rootid
10/2/2018 - 3:52 PM

Show files changed in a specific git commit

The one I want to use 95% of the time:

git diff-tree --no-commit-id --name-status -r <commit-ish>

From StackOverflow's How to list all the files in a commit? :

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.
  • The --name-status argument shows the file names and how they were changed
  • The -r argument is to recurse into sub-trees

If you want to get list of changed files: git diff-tree --no-commit-id --name-only -r <commit-ish>

If you want to get list of all files in a commit, you can use git ls-tree --name-only -r <commit-ish>

If you want to get a list of all new files in a commit, you can use: git diff-tree -r --name-only --no-commit-id --diff-filter=A <commit-ish>