I know I can link to a specific line number on a file on a github repo (I'm sure I've seen this before)...
Can someone tell me how to do this?
This question is related to
github
For a line in a pull request.
https://github.com/foo/bar/pull/90/files#diff-ce6bf647d5a531e54ef0502c7fe799deR27
https://github.com/foo/bar/pull/
90 <- PR number
/files#diff-
ce6bf647d5a531e54ef0502c7fe799de <- MD5 has of file name from repo root
R <- Which side of the diff to reference (merge-base or head). Can be L or R.
27 <- Line number
This will take you to a line as long as L and R are correct. I am not sure if there is a way to visit L OR R. I.e If the PR adds a line you must use R
. If it removes a line you must use L
.
Many editors (but also see the Commands section below) support linking to a file's line number or range on GitHub or BitBucket (or others). Here's a short list:
You can you use permalinks to include code snippets in issues, PRs, etc.
References:
https://help.github.com/en/articles/creating-a-permanent-link-to-a-code-snippet
Click the line number, and then copy and paste the link from the address bar. To select a range, click the number, and then shift click the later number.
Alternatively, the links are a relatively simple format, just append #L<number>
to the end for that specific line number, using the link to the file. Here's a link to the third line of the git
repository's README
:
Related to how to link to the README.md
of a GitHub repository to a specific line number of code
You have three cases:
We can link to (custom commit)
But Link will ALWAYS link to old file version, which will NOT contains new updates in the master branch for example. Example:
https://github.com/username/projectname/blob/b8d94367354011a0470f1b73c8f135f095e28dd4/file.txt#L10
We can link to (custom branch) like (master-branch). But the link will ALWAYS link to the latest file version which will contain new updates. Due to new updates, the link may point to an invalid business line number. Example:
https://github.com/username/projectname/blob/master/file.txt#L10
GitHub can NOT make AUTO-link to any file either to (custom commit) nor (master-branch) Because of following business issues:
@broc.seib has a sophisticated answer, I just want to point out that instead of pressing y
to get the permanent link, github now has a very simple UI that helps you to achieve it
Select line by clicking on the line number or select multiple lines by downholding shift
(same as how you select multiple folders in file explorer)
on the right hand corner of the first line you selected, expand ...
and click copy permalink
https://github.com/python/cpython/blob/c82b7f332aff606af6c9c163da75f1e86514125e/Doc/Makefile#L1-L4
Source: Stackoverflow.com