How to list all files in a commit? To list all files in a Git commit, you can use the git show command with the --name-only or --name-status option. Here's how to do it:
- Using the
--name-onlyoption:
shgit show --name-only <commit-hash>
<commit-hash> is the hash of the commit you want to inspect. This command lists all file names that were changed (including additions and deletions) in that commit.
- Using the
--name-statusoption:
shgit show --name-status <commit-hash>
This command not only lists the file names but also shows the status of each file, such as M for Modified, A for Added, and D for Deleted.
If you only want to obtain the file list without seeing other commit details (such as diff or commit message), you can use --pretty=format: to suppress additional output:
shgit show --pretty=format: --name-only <commit-hash>
Or:
shgit show --pretty=format: --name-status <commit-hash>
If you don't know the commit hash but know it's the most recent commit, you can use HEAD to reference the latest commit, or HEAD~1 for the previous commit, and so on. For example, to list all files in the most recent commit:
shgit show --pretty=format: --name-only HEAD
Additionally, if you want to view which files were modified in the last commit of a specific branch or tag, replace HEAD with the branch name or tag name. For example, to view the last commit of the feature-branch branch:
shgit show --pretty=format: --name-only feature-branch
Using these methods, you can easily view all files included in a Git commit.