List filenames changing on a PR

I’m running a script on an Azure DevOps Agents and I’d like to list the name of files changing on a PR. On the agent checkout task I can see we are in a detached state:

git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/pull/1/merge:refs/remotes/pull/1/merge
remote: Enumerating objects: 31, done.        
remote: Counting objects:   3% (1/31)
<output truncated>

 * [new branch]      main              -> origin/main
 * [new branch]      test              -> origin/test
 * [new ref]         refs/pull/1/merge -> pull/1/merge
git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules origin +048dfd62ee6cc8346faf1f8b69d6b6bb2ff6c68d:refs/remotes/origin/048dfd62ee6cc8346faf1f8b69d6b6bb2ff6c68d
 * [new ref]         048dfd62ee6cc8346faf1f8b69d6b6bb2ff6c68d -> origin/048dfd62ee6cc8346faf1f8b69d6b6bb2ff6c68d
git checkout --progress --force refs/remotes/pull/1/merge
Note: switching to 'refs/remotes/pull/1/merge'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 048dfd6 Merge 82b12c8c091be60b74ca172a56141d784de168b4 into 8111414018335ff8397b272297a8b06c56db7fa5

When using git diff-tree (see command below) I’m able to list the file changing but only those of the first commit are recorded:

git diff-tree --no-commit-id --name-only -r HEAD^

How can I list all the files changing when compared to main whilst on a detached HEAD state as above?

Thanks in advance!