Listing changed files in a commit

Use below command to list the changed files in a commit:

# List changed files in the specified commit
$ git show --name-only <commit>

# Examples

# List changed files in HEAD
$ git show --name-only HEAD
commit ea34837d870e48106ae9ad09f41297a64ad6a6a1 (HEAD -> master)
Author: xxx <xxx@xxx.com>
Date:   Wed Mar 13 20:27:46 2019 +0800

    feat: add localization

my-plugin.php
languages/my-plugin-zh_CN.po

If you only want the file names, use:

# List only names of changed files in HEAD
$ git diff --name-only HEAD~ HEAD
my-plugin.php
languages/my-plugin-zh_CN.po

Getting contents of a file in a specific commit in Git

Use below command to show contents of a file in a specific commit:

# Get contents of a file in a specific commit.
# <commit>, specify the commit, such as an commit id.
# <file-path>, file path of relative to the current directory.
$ git show <commit>:<file-path>

Examples:

# Get contents of asset/css/style.css in commit 8bc723c
$ git show 8bc723c:asset/css/style.css

# Get contents of asset/css/style.css in the parent commit.
$ git show HEAD~:asset/css/style.css