0

I also need to require to list the list of files modified in particular pull request in Azure DevOps services.

I have checked some threads, like List changed files of a Pull Request using powershell or git, but it not given the solution. Most of the answers are for github, not azure devops.

So, I'm wondering if there is such a direct git command to fetch it, and if not, how can this be achieved using the corresponding Azure Devops REST API script? Please help.

Background:

I created a pipeline which is triggered by the PR (Build Validation) on the SIT branch:

enter image description here

The configuration of the pipeline is as follow:

enter image description here

The ModifiedFileTest is the my test branch name, which based on the SIT branch:

The output:

enter image description here

Joy
  • 1,171
  • 9
  • 15

2 Answers2

2

If you have up to date branches in your local clone, the diff or the "merge request view" for branch feature into main is:

git diff origin/main...origin/feature   # 3 dots, not a typo

note: the behavior of this syntax is documented in the "Description" section of git help diff

It basically shows the diff between origin/feature and "the point where it forked off origin/main", and all the platforms I know of (github, gitlab, azure devops, bitbucket ...) show this diff in their "Pull Request" view.


You can add any other suitable option to git diff, like --name-only or --name-status :

# list of files modified in 'feature':
git diff --name-only origin/main...origin/feature

# list+status of files modified in 'feature':
git diff --name-status origin/main...origin/feature
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Thanks for your input, but I got the error message "fatal: ambiguous argument 'branch1...branch2': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]'" – Joy Mar 28 '23 at 09:20
  • That's the error you get when one of the names you used doesn't exist. Double check the names you typed for your branches. – LeGEC Mar 28 '23 at 09:55
1

LeGEC's answer is correct.

In Azure DevOps Pipeline, you need to set the remote source, then you can run git diff to get the changed files.

Example:

git remote add  origin1 RepoURL
git remote update    
git diff  origin1/test  origin1/master

Then we can get the changed files.

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28