1

I am using Azure Devops Repos. I have one branch: "master", with this history:

*  🔵 HEAD - Commit 7: Fix production bug (sha: 1a2b3c4)
|
*     Commit 6: Add health checks (sha: a1b2c3d)
|
*     Commit 5: Improve performance (sha: b2c3d4e)
|
*  🟡 Commit 4 (selected): Refactor auth logic (sha: abc1234)
|
*     Commit 3: Add login API (sha: c3d4e5f)
|
*     Commit 2: Set up CI pipeline (sha: d4e5f6g)
|
*     Commit 1: Init project (sha: e5f6g7h)

I would like to do a visual comparison (in the Azure UI) between "🟡 Commit 4" and "🔵 HEAD - Commit 7". A view which will show me summary of all files which were changed, and the specific changes. Something like we have when we click a specific commit, or when we visualise changes of pull request: enter image description here

Is there a way to do it in Azure Devops? I know I can compare branches and I can see changes for a single commit, but I would like to see differences for more commits gathered together, similiar like I can do it in IntelliJ just by selecting more than one commit.

7
  • There are so many good clients for comparing commits, I'm curious why you would prefer to do it online? Also, how far away is commit 1 from HEAD? (How many additional commits could HEAD reach that commit 1 can't reach?) Commented Jul 16 at 23:17
  • 1
    OK. I asked for the number because I'm curious if many is typically more than 100. There is a klunky solution you can use by creating a temp branch at the starting commit using the AzDO UI, and then going through the motions of creating a PR which would merge master into temp-branch. You don't even need to actually create the PR, and you can see the diff like you desire. But, I'm pretty sure that About-To-Create-A-PR screen only diffs the first 100 commits. You'd actually have to create the PR to see all the files if there are more than 100 commits. Commented Jul 17 at 16:27
  • 1
    I suppose if you want a link to share, you'd need to actually create the PR so you could share it- perhaps use a Draft PR for this purpose. Again, this is kind of klunky, but if you think it could be useful lmk and I'll write it up as an option. Commented Jul 17 at 16:29
  • 1
    I just realized that you could also use the branch compare with the newly created branch like in juunas's answer. And then I realized that answer is perfect because it also works with commit IDs. You should go accept it! I edited that answer with details on how I got it working. Commented Jul 21 at 20:08
  • 1
    Indeed it worked. I have used the url: dev.azure.com/myorg/myproj/_git/myrepo/… Commented Jul 22 at 8:19

1 Answer 1

1

Based on this extension's source code, it seems it is possible through a custom URL, e.g.

https://dev.azure.com/yourdevopsorg/_git/yourrepo/branchCompare?baseVersion=GCsourcecommithash&targetVersion=GCtargetcommithash&_a=files

Replace:

  • "yourdevopsorg" with the name of your Azure DevOps organization
  • "yourrepo" with the name of the repository
  • "sourcecommithash" with a commit SHA hash
  • "targetcommithash" with a commit SHA hash

Note that the version refs need to be prefixed with either "GB" for "Git branch", or "GC" for "Git Commit", and GC must contain the full 40 character hash. So in your case, if you are comparing commit 4 (abc1234) with master, the syntax would be:

https://dev.azure.com/yourdevopsorg/_git/yourrepo/branchCompare?baseVersion=GCabc1234xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&targetVersion=GBmaster

Also note that this uses a 3-dot diff instead of 2-dot, so it only works in 1 direction. If you get no results try swapping the order of your refs.

The extension I linked looks like it'll add buttons to do this for you. Why this isn't a feature out of the box, your guess is as good as mine :D

Sign up to request clarification or add additional context in comments.

4 Comments

@junnas I like this solution a lot, unfortunately did not work for me. When I tried to use the url I got an error: "An unexpected error has occurred within this region of the page. You can try reloading this component or refreshing the entire page.". When I check the HTTP call which produces this error ( from developer tools tab) I see more specific exception: "Error: Unrecognized VersionSpec format.\n at t.<computed>.gitVersionStringToVersionDescriptor ". Although I copied SHA hash directly from Azure Dev.
@junnas I did a mistake with SHAS and removed also the GC from the link. so instead of GC42343fadsfds I was putting simle : 42343fadsfds. After correcting this mistake I have no error. but still although there were changes between those commits The page shows me message: "No changes between these branches."
Try using the full 40 char hash. If that doesn't work try swapping the order of your refs. This compare screen uses a 3-dot syntax so it will only work in one direction. (Here's an unrelated answer which explains why the 3-dot syntax is used.) I also edited this answer in case you're mixing branches and commits together.
I have used url : dev.azure.com/myorg/myproj/_git/myrepo/… and got the changes as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.