Search code examples
gitgit-diff-treegit-plumbing

Get a list of changed files and their status for a specific Git commit


I use the following Git command

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

to get a list of changed files.

Unfortunately, the list doesn't specify the type of change for each file: added, modified or deleted ... etc

How may I display a list of changes [type of change, file name] in a given SHA of a specific commit.


Solution

  • Use --name-status instead of --name-only

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

    This will show the filename with a status letter of (extracted from man): Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B).