Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

gitlab-ci

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?

like image 359
Roy Avatar asked Apr 26 '26 14:04

Roy


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
like image 173
LeGEC Avatar answered Apr 28 '26 03:04

LeGEC