Are there any Azure CLI commands that will return information about PR branches that have commits not merged into target branch. I am working through some automation and need to determine if there are any commits on a PR branch that have not been committed to the target branch.

In azure devops (ADO) when you start to create a PR, it will show you the number of files and commits like the image below. I am trying to determine if there are files or commits like the image below shows 1.

I tried these but could not see anything related in the return

azure repos pr show

Azure repos pr create

Thanks in advance.

enter image description here

1

There are 1 best solutions below

0
Alvin Zhao - MSFT On

As of now, there seemed to be no Azure CLI command for Azure DevOps pull request to compare and list the changed files/commits from source branch pending merged to target branch.

However, you may use git diff command to check the modified files between branches. Here is a simple sample for your reference.

git diff --name-only main..Branch1

And we can use git log to list the new commits.

git log main..Branch1

enter image description here

See more discussions and samples based on different usage scenarios in the threads below.

diff - How to get a list of different commits between two git branches? - Stack Overflow

git - How do I see the differences between two branches? - Stack Overflow

By the way, we can use this API to get git diff between branches. In my case, I created a PR to merge BranchB to BranchA.

            "title": "PR: B->A",
            "sourceRefName": "refs/heads/BranchB",
            "targetRefName": "refs/heads/BranchA",

Then I called the sample API and got the response like below.

https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{TheRepoName}/diffs/commits?baseVersion=BranchA&targetVersion=BranchB&api-version=7.1-preview.1

enter image description here

Hope the information would help.