I want to link to a line of code in such a way that the link will continue to work even when the file is updated in future commits.
In Github I would do this by pressing 'y' to move to a version of the page that includes the blob SHA:
https://github.com/rails/rails/blob/b49e38b76b0998b0a8312d8c08c98728d3de2006/activerecord/lib/arel/attributes/attribute.rb#L30
(Alternatively GitHub has a 'copy permalink' option in the '...' menu that appears in the margin when you select a line - documented here.)
Is there an equivalent in Azure DevOps?
The link that I get when I select a line has the form:
https://.../_git/project?path=XXXX&version=GBmaster&line=426&lineStyle=plain&lineEnd=427&lineStartColumn=1&lineEndColumn=1
Lots of parameters defining the selection but nothing pinning the file version.
Open a work item and choose the Links tab. From the links control tab you can link to new or existing work items, open the linked object, edit the link type, delete a link, or open the list of links in a query or Excel or Project. The work item form opens in the web portal for Visual Studio 2017 and later versions.
GitHub link types are system-defined link types. They support linking work items to GitHub objects as shown in the following image.
My flow needs to update a DevOps work item with a hyperlink. This can be done manually through the DevOps user interface by adding an existing item and selecting Hyperlink as the link type.
Make sure you're browsing the entire source for the commit. Selecting lines when viewing the commit itself (ie AzDOs fancy git show) is for adding comments to the commit, but it doesn't help produce a link to the line @ that version, nor is there a way (at least not that I could find) to get a link to the comment made on the line. Getting a link to a comment on a line in a commit might have been helpful to provide additional direct context to what is linked and why, but that's also not what you asked for.
The below illustrations can be summarized in a few keyboard shortcuts.
You should be able to select a line in the file contents and get a link to that line(s) in that version.
note: the link produced here is even more lengthy than the one you provided in your question.
When you navigate to the copied link, you will be directed to the commit and file contents with the line highlighted.
Using the @username
syntax in the comment editor might be a good solution to "share" a selection from the code. However, this method requires that you find the actual commit in which the change was made. Using the "browse files" method above allows you to share the address to a particular selection from any commit with the changes to be shared.
Thank you @JoshGust. For anyone else who wants the abbreviated version:
Sheesh... quite some hoops to jump through, but glad it's possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With