3

When answering questions on Stack Overflow or GitHub itself, I often have this process:

  1. Browse code in GitHub UI
  2. Go to relevant file
  3. Find relevant line
  4. Click the margin of that line to get the URL to that specific line

The result: a link to e.g. .../my-lib/blob/master/src/main.ts#L123

My intended result is to get a link to that line with a URL that points to the specific commit I'm viewing, because I want my link to be 'stable': if you click it one year from now I want to be reasonably sure it'll show the same code.

Is there a nice way to do this in the UI? Currently my process is a bit hacky:

  1. Scroll to the top of the file again
  2. CTRL + click on the short hash top right of the file pane
  3. Copy the full hash from the URL bar
  4. Close the tab
  5. Replace "master" with the copied hash
  6. Hit enter to verify you go to the right line in that specific commit
  7. Copy the current URL

I feel like I'm missing some kind of navigation feature to do this?

2

This functionality is available in Github:

Start with your normal 1. to 4., then:

  1. Click the ... that appeared left next to the line you clicked on
  2. Select "Copy link"
  3. Use the link in your clipboard to link to a static, forever valid version of the current file

Example: https://github.com/apache/cordova-lib/blob/master/cordova-lib.js#L15 becomes https://github.com/apache/cordova-lib/blob/17508a757c16e4fa6255a0e568907465af471bf9/cordova-lib.js#L15

1

A more comfortable way in my opinion, is going first to the commits tab, select browse files < > and then continue as you described in the first process.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.