How Do I List All the Files in a Commit?

Better Stack Team
Updated on June 24, 2024

To list all the files in a specific commit in Git, you can use the git diff-tree command. Here's how you can do it:

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

Replace <commit-hash> with the hash of the commit you want to list the files for.

This command will list all the files that were affected by the specified commit. Each file will be listed on a separate line.

Alternatively, if you want to see the changes introduced by a specific commit, including the list of files and the modifications made to each file, you can use:

 
git show --name-only <commit-hash>

This command will display the commit message, followed by the list of files and the changes made to each file in the specified commit.

Note:

  • Replace <commit-hash> with the hash of the commit you're interested in. You can find the commit hash using git log.
  • The git diff-tree command is useful for listing files without showing the actual changes, while git show displays both the files and the changes made in the commit.
Got an article suggestion? Let us know
Explore more
Git
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.