Azure DevOps-比较 web UI 中的两个提交?

我肯定忽略了一些简单的东西。在 Azure DevOps Web 界面(没有作为 IDE 的一部分集成)中,我看到了如何将任何提交与其父提交进行比较,但是我不知道如何将其与任意提交进行比较。

也就是说,我在寻找相当于 GitHub 的比较/hash1. . hash2的功能。

吸引人的地方在于,web UI 是每个人都可以使用的视图/工具,而且我可以得到一个链接,指向我感兴趣的具体差异,并与同事们分享。

Web UI 建议使用 也许吧是可能的,因为当查看某个特定提交的更改时,它有文本 Diff to Parent 1 - <my commit hash>,但是我还没有弄清楚如何更改 Parent 1

41289 次浏览

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

https://learn.microsoft.com/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://learn.microsoft.com/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.

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.

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.

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