Linking to a line of code in a particular version of a file in Azure DevOps (VSTS) - azure-devops

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.

Edit:
The below illustrations can be summarized in a few keyboard shortcuts.
Open the repo Files view using the 'e' global shortcut
Use 't' to put focus on the path selection to quickly navigate to the file in question
point 2 and 3 are order agnostic in relation to one another
Use 'y' to change the Files view to be based on the latest commit instead of on the branch
Make selection
Copy link as shown in illustration below
Browse files on the commit
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.
don't click on the commit itself
make sure you're browsing all files as of a commit (not a branch)
Make selection
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.
Joy
When you navigate to the copied link, you will be directed to the commit and file contents with the line highlighted.
Understand, this link is bound to the commit you used to create it not to the tip of the branch. I expect this was how links are surfaced to be more sure that the link wouldn't break or lose context as the commit at the tip of the branch changes over time.

Thank you #JoshGust. For anyone else who wants the abbreviated version:
Files -->
(your repo branch) -->
History -->
Click A Commit hash/number (Latest/Head usually) -->
Browse Files -->
Your file -->
Select text & get a link.
Sheesh... quite some hoops to jump through, but glad it's possible.

To create a web (repository) link to a specific line from within your IDE, there are extensions with options to link to files, selections, to a branch or to a specific commit.
I am using these ones:
Editor
Plugin
Visual Studio Code
Git Web Links for VS Code
Visual Studio 2022
Git Web Links

Related

How to get permanent link to a file with BitBucket server?

Sometimes I want to provide a link to some source code in the comment to an issue.
If I open repository in browser and find the fileI need, the link refers to master branch by default. It means that over time the code referred by the link will change, because the master will move together with commits history.
In GitHub and GitLab when you want to get a permanent link on a file you just opened, it is enough to press y on the keyboard and the link will switch from referring the master branch to particular commit hash it points to.
I.e. https://github.com/octocat/Hello-World/blob/master/README -> https://github.com/octocat/Hello-World/blob/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d/README
At work I use BitBucket server (v7.10.1, if it matters) and unfortunately the y does not work, and I also do not see any button on UI to get permanent link. How can I achieve the same result (get permanent link) on BitBucket server?
I know a couple of tricks I am not satisfied with:
using Bitbucket Linky plugin for Intellij, but I want a more light-weight way
pressing History button on a file, and choosing the most recent one (but it does not give you the master hash, it gives the hash of the last change of the file. And also this button won't work if the file has a single version and never changed after the 1st commit)
Got to the version you want, and then click 'Raw file' (top right hand side of screen)
The path in the address bar should now be a permanent link. It will be the raw version of the file unfortunately, but it is a permanent link.

Link to a specific branch, tag or commit, or a specific file within it, or a specific line within that file?

I create a tutorial, where I want to introduce some testing frameworks like Mockito, WireMock and EasyMock. I want to explain it step by step. Additionaly I want to provide examples, where the reader of the tutorial can try to recreate these. Therefore I want to to give them the opportunity to look into my source code and use it when they are not able to recreate the test. And then they can use the actual version to continue and then again, when they are not able to create the next test, I want to to give them the possibility to use my new version with the new test.
My idea is to use different commits and link them to the tutorial. How can I do this or is there any better approach to reach what I just explained?
Easy Peasy!
The basic approach is this: browse to exactly what you want on GitHub, and then share the URL. GitHub URLs are stable permalinks, even when you navigate to an old revision or another branch.
Open the repo in Github.
Browse to Branch, tag or commit you want.
For branch/tag, there's a drop down in the upper left of the files listing.
For a specific commit:
Click on Commits at the top of the files listing. This will take you to a page showing all the diffs. (You can share this URL if you want. Otherwise continue to the next step.)
Clink on Browse files in the upper right corner.
You are now looking at a repository view just like the one where you started, except this view is of a specific branch, tag or commit. It's like a GitHub time machine.
If you want to link to the entire repo at this branch/tag/commit, copy the URL right now.
If you want to link to a particular file at this branch/tag/commit, navigate to the file in the listing, then copy that URL.
If you want to link to a particular line in the file, click on a line number, then click on the ... button that appears next to it and then click Copy permalink
If you want to link to a range of lines in the file, hold down the shift key and clink on the other end of the range of lines. The lines will be highlighted. Click on the ... button that appears next to it and then click Copy permalink
All that said, unless you are walking them through your many iterations of the code, I'm not sure giving them links to versions in git history is the way to go. Let's say they want to clone your repo. Then they'd have to git checkout example-2-version-3 or something.
The more typical approach is to put the different versions in a directory hierarchy, making it far easier to browse, whether on GitHub or a local clone of your repo.

Github for mac - pushing selected files only

I'm new to github and currently only starting off using github for mac.
I have taken a clone of my client's website and made some development changes locally. Note: I'm literally working with the files in the directory I sync with.
I want to push only one small change as the rest is still under development. Is it possible to push only the one file?
Git pushes deal with commits, not files. You'll need to create a commit that contains your selected changes. This is one area where Git's index is really handy.
Let's say you've modified two files, foo and bar.
If you want to commit only the changes to foo, using the command line you can do
git add foo
git commit
This will create a new commit updating foo, but bar's changes will remain only in your working copy. You can now push the new commit.
It's been a while since I've used the graphical GitHub tools, and I've only used them on Windows, but I believe the way to commit only certain files is to check or uncheck the box beside each file before you commit. You can see these checkboxes in their documentation:
You can go even further. If some of the changes in bar should be part of a commit, but not all of them, you can do something like git add --patch, which will break your changes up into chunks and prompt you for the ones to add to the index (these are the ones that will be included when you commit).
On GitHub for Mac you can do this too:
Select one or more lines to commit by clicking on the line numbers in the gutter. In the latest release, you can select a block of changes at a time. Hover over the right hand side of the line numbers to get a preview of what will be selected, and click to select.
See the documentation for git-add for details.

Comment on a line in Github without a commit?

In github, you can comment on lines in a commit. Is there a way to comment on a line, while viewing a file in a branch, without having a particular commit?
Unfortunately it is not possible to comment on a line in Github without a commit.
But you can create links to lines in your file (click on line and copy link on browser bar). For example you can use this links in your issues to discuss about code line:
https://github.com/sebastianbergmann/phpunit/blob/master/src/Runner/StandardTestSuiteLoader.php#L72
Update
You can also hold shift to obtain a link to a block of lines
You should have at least one commit: your initial import ;-) So if you never touched the file afterwards, you can still browse your master branch (or wherever you did the initial import to).
To get to a commit of file, do as follows:
open homepage of your repo, e.g. here Ruby on Rails
browse to the file you like to comment, e.g. Rails' .gitignore file
there's a button called history, click it to see latest commits of this file
look for a commit and click the link with the revision ID
You should now be able to comment the file.
This blog post provides a simple way to use github's built-in commenting features for this:
http://astrofrog.github.io/blog/2013/04/10/how-to-conduct-a-full-code-review-on-github/
I wanted to do the same thing, for a code review.
I ended up:
forking the repo
adding my comments in the source code (e.g. // TODO: ...)
making a pull request
The only way if you use a different tool for this job. I use Fisheye, or Review-Board for do pre-commit revision code.
Review Board is free, and handle better than Fisheye the pre-commit code.

How do you see the changes for a version in TFS?

I'm trying to migrate to TFS from VSS and I need to be able to show what files were checked in between two releases. In VSS we would just label the code for a release and view history between labels and generate a report to show the checkins and the comments. Is there a way to get similar results with TFS? Or show the differences between two changesets or labels?
The command line tool tf.exe gives you more options than the GUI (and can either give results in a Dialogue or as standard output --- good for feeding into further processing).
E.g.
tf hist . -r /version:C10~C1000
will list all the changesets affecting this folder and content recursively between changesets 10 and 1000.
See the documentation on MSDN.
If you need maximum flexibility, you can create your own commands using the TFS client assemblies. Unfortunately documentation is somewhat sparse.
Right click on your desired folder on TFS (e.g. the root folder), you'll find following two options:
1, Apply Label - this allows you to apply label to a particular version of that folder.
2, Compare - this allows you to compare that folder between versions, and one of the choices is comparing by label.
Right click on any node in TFS Source Control and choose 'View History'
This will show you all changesets ordered by date descending.
Double click on those and you can see the detail about the change set: the comment, associated work items, and files that were changed.
As Jeff said, right-click on the project, any folder or file, and choose "View History" to see all changes. If you know when your labels were applied, it's easy to scroll down this list until you hit a particular date/time.
For an exact list between two labels or changeses, use "tf.exe history" (as Richard says) from a Visual Studio command prompt (in your start menu in the Visual Studio 2005 folder). For more info on this just execute "tf.exe help history".
For day to day changes, if you use TFS build you can see the changes since the last build at the bottom of the build information page (Double click the build name in Team Explorer, then double click the specific build. Scroll to the bottom of this page and open "associated changesets". I've set out CI build to not associate changesets, which means that our daily test build lists all changesets since the previous daily build - a great summary of the changes for our testers to get their teeth into.
I was using the command line tf hist and getting the changesets to compare by finding the highest changeset in a label or branch changeset, but having a manual process and using the command line didn't go over too well here. I used Carl Daniel's code to write a little web application that will bind the changes to a datagrid.
If you're looking for something special the standard interface doesn't give you it's fairly simple to write your own application that links into TFS. I'd definitely suggest it.