Azure DevOps - compare two commits right in the web UI?
Asked Answered
S

5

123

This is surely something simple I'm overlooking. In the Azure DevOps web interface (not integrated as part of an IDE), I see how to compare any commit to its parent, but I can't figure out how to compare it to an arbitrary commit.

ie, I'm looking for the equivalent of GitHub's compare/hash1..hash2 functionality.

The appeal is that the web UI is a view/tool common to everyone, and presumably I could get a link to the specific diff I'm interested in and share it with colleagues.

The web UI suggests it might be possible because when viewing the changes for a particular commit it has text Diff to Parent 1 - <my commit hash> but I haven't figured out how to change Parent 1.

Somnifacient answered 30/12, 2019 at 16:26 Comment(1)
agreed - microsoft UI, every time...smhPepe
D
197

If you go to the list of branches for a repository, you can click on ... (More Actions) on one of the branches and choose Compare branches

This will take you to a URL in the form: https://dev.azure.com/{organisation}/{project}/_git/{repository}/branches?baseVersion=GB{baseBranch}&targetVersion=GB{targetBranch}&_a=files

You can then change the baseVersion and targetVersion parameters in the query string. These can take the following forms, and can be mixed and matched:

  • GB{branchName}
  • GC{commitHash}
  • GT{tagName}

Just in case that link gets broken, clicking "View Merge Changes" on a pull request takes you to the same page but with a slightly different URL https://dev.azure.com/{organisation}/{project}/_git/{repository}/branchCompare?baseVersion=GC{baseCommit}&targetVersion=GC{targetCommit}&_a=files

I'm not sure if there's a nicer way of comparing commits from the UI, as it only shows branches and tags, but if you do it this way you don't have to temporarily tag commits or create temporary branches just to get a diff that shows all of the changed files.

Disseise answered 14/2, 2020 at 16:11 Comment(5)
Just want to add a comment that if you get the commits backwards in the URL, it will just tell you that there are no changes between the two commits (instead of an error message or something). Try flipping them around.Irwin
Nice! Too bad they don't have an easier way to do thisEndowment
This is exactly what I was looking for. Thanks for sharingCalais
... then click the "Files" tab to see the changed files with the added and deleted lines marked appropriately.Lengthwise
I found that the link (the second one, with “branchCompare” as the last path segment) would not work unless I pasted full-length commit hashes for baseCommit and targetCommit. (At least it would not work with a branch name in one place and also not with the 8-character abbreviated commit hashes that are shown in the user interface.)Hord
T
37

If you want to compare two arbitrary commits for one file, navigate to the file in the repo, select the compare tab, and apply the appropriate commit range.

enter image description here

If you want to compare two arbitrary commits for all files , you can create tags at commits , then compare them. This will give you a list of commits between them and allow you to show the diffs.

enter image description here

enter image description here

enter image description here

enter image description here

For details, you can refer to this case.

Tsaritsyn answered 31/12, 2019 at 8:51 Comment(4)
thanks Hugh! creating tags is not my preference, but it certainly works in a pinch.Somnifacient
Absolutely amazing answer!Mallette
This answer is great and should be marked as "Answer". This is the way how to compare arbitrary commits right from the user interface.Staffer
New branch... from History also works to compare arbitrary commits (branches in this case). That is, creating shord-lived branch that you can then compare and delete. Ofcourse one may prefer using tags... Love that it automatically names the branch (that includes the commit hash), but it does for tags too... so perhaps no particular advantage.Capo
A
14

The Devops UI does now allow a comparison of the commits between branches as well as files. The URL is very similar to the one detailed in George Heylar's answer, you just change the end of the URL from 'files' to 'commits':

https://dev.azure.com/{organisation}/{project}/_git/{repository}/branches?baseVersion=GB{baseBranch}&targetVersion=GB{targetBranch}&_a=commits

The short way to do that via the UI if 'Compare Branches' is not disabled

  1. Open the Branch list for your project:

Azure DevOps Branch list

  1. Click the vertical ellipsis button against the first branch you want to compare:

Branch row options list

  1. Select 'Compare branches' to open the screen below. If the 'Compare branches' option is disabled see the longer approach below.

Top of the Branch compare page

  1. Select the branch to compare to in the second combo and then you will see a list of the commit differences between the two branches:

Branch compare page showing commit differences between master branch and a release branch

  1. If you want to see the file differences just choose the 'Files' option in the not terribly obvious tab control:

Compare Commits or Files tab

The long way to achieve that via the UI if 'Compare Branches' is disabled

  1. Open the Branch list for your project:

Azure DevOps Branch list

  1. Click the vertical ellipsis button against the first branch you want to compare:

Branch row options list

  1. Select 'Set as default branch'

  2. Repeat the same process for the second branch you want to compare to:

Branch row options list

  1. This time select Select 'Set as compare branch'

  2. Finally open the ellipsis menu again for the branch you set as the default branch (i.e. the one you picked in step 3 above)

Branch ellipsis menu when default and compare branches have been selected

  1. Select the 'Compare branches' menu item and that will open the 'Branch Compare' page:

Branch compare page

Amylase answered 26/7, 2021 at 11:59 Comment(2)
fantastic. I'm going to leave George Haylar's answer as the selected answer tho, as the Q is really about Commits, vs. Branches, but I'm very grateful you pointed this out anyhow. I'll use it all the time.Somnifacient
Although this is quite similar to my answer, this actually only lets you compare branches or tags, not arbitrary commits (without changing the URL as I described), and you shouldn't be changing your default branch for this reason. The default branch is e.g. master or main, and it's a repository-wide setting, not a personal setting. You can change your "compare branch" and then "compare branches" on another branch, but again this doesn't let you compare arbitrary commits, and it's just as easy to leave your default branch as your compare branch and change them on the comparison page.Disseise
V
1

The "Diff to Parent 1" feature is described in "Commit details / What are the changes included in the commit?"

https://static.mcmap.net/file/mcmap/ZG-AbGLDKwfsXV_wai2tZVMwa1MvXn3QWRft/en-us/azure/devops/repos/git/_img/commit-details/10difftoparent.png?view=azure-devops

Diff to parent - Click on Diff on parent1 in the Source Explorer pane to view the difference between the current commit and its parent commit.

One can see what Parent1 references in the diff view itself:

https://static.mcmap.net/file/mcmap/ZG-AbGLDKwfsXV_wai2tZVMwa1MvXn3QWRft/en-us/azure/devops/repos/git/_img/commit-details/11sidebyside.png?view=azure-devops

But I don't see any web URL which could help reference that diff. Hence my initial Azure DevOps Git API that I proposed before.

Virago answered 30/12, 2019 at 16:43 Comment(3)
So there is no answer to #61059602 ?Scraggy
@Scraggy None that I know of indeed. Let's see if someone has an answer to your question.Virago
I've looked into doing a manual HTTP call to the route mentioned, but it's near impossible to get file paths and commit IDs from the API SDK properly. I'm giving it up for now, until someone has a golden tip. But I don't count on it. :)Scraggy
D
0

Easy...

If you would like to compare two commits of a branch...

  1. Go To branches.
  2. Create a new branch from branch where you want to do comparison.
  3. Create branch with the specific commit. enter image description here
  4. Compare newly created branch with original branch.
Dichotomous answered 11/9, 2023 at 6:44 Comment(3)
hm, thanks for this idea, but I'm not crazy about modifying the repository just to examine it.Somnifacient
Some of the other answers already cover the idea of creating temporary branches (or tags) to permit comparison of commits - perhaps it would be better to suggest an edit (once you have the appropriate permissions) on one of the other answers?Infernal
................Dichotomous

© 2022 - 2024 — McMap. All rights reserved.