3

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?

Roy
  • 398
  • 1
  • 6
  • 20

1 Answers1

5

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
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • 1
    Note that this literally asks Git to diff the two `resources` sub-trees within the commit. You could also use `git diff-tree -- resources`, which diffs the top level trees but limits the *reporting* to the `resources` subtree within each top level tree. The effect is the same (and the efficiency should be similar), but using the colon syntax allows you to, e.g., diff commit1's foo/bar subtree vs commit2's baz/raz subtree. Just a side note, really. – torek Aug 09 '21 at 18:39