Get number of lines changed between two tags in azure devops repos using rest api

Viewed 40

I'm trying to get the lines of code that has been changed (added, edited or deleted) between two tags in Azure Devops repos using the following apis

It seems the changeCounts in response represent the file changes not the lines of code changes.

Then I tried to use the single commit id in the response to hit the following endpoint - https://docs.microsoft.com/en-us/rest/api/azure/devops/git/commits/get-changes?view=azure-devops-rest-7.1&tabs=HTTP

It doesn't help as it doesn't have all the commits.

1 Answers

I've tried it with two different branches by the following URL.

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

Please keep in mind, if you swap baseVersion with targetVersion you'll not get the count. baseVersion should be behind the targetVersion


If you want to compare two commits then you've to specify baseVersionType=commit and targetVersionType=commit

https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/diffs/commits?baseVersion=288a82985bbb725a23699a9d15b9d23b6510f689&baseVersionType=commit&targetVersion=8379363a3154627993f2c358cee347b7c64bc836&targetVersionType=commit&api-version=7.1-preview.1
Related