How to 'git diff-tree' on a certain directory?

Viewed 618

I need a list of files that changed and dump it to the files

I can get all the list by running this git diff-tree --name-status -r "upstream/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME..HEAD" > changed-files.txt

But now I want only a list of files that changed inside the resources folder only

How to do that?

1 Answers

You can target a subdirectory within a commit using the following syntax :

<commit hash or name>:path/to/dir

In your case, you can change your git diff-tree command to :

git diff-tree --name-status -t \
    "upstream/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME":resources \
    HEAD:resources

As @torek comented, you can also simply provide a path after the compared elements, to narrow the diff to that path only, so the following command also works :

git diff-tree "upstream/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" HEAD -- resources
Related