How to access a specific line or range of lines in github?

If you want to add a link to a specific line or series of lines, it would be nice to get a URL that does this.

+7
github
source share
2 answers

Note that the problem with #Lxx-Lyy is that (from this post ):

source files can be changed or even deleted, so theres no guarantee that your link will always point to the right place .
By default, GitHub project pages link to the latest source version. The best practice is to link to a specific commit, where the contents of the source files are not subject to version control.

To view the GitHub project with a specific commit, click the tree link in the commit header or just press t on the keyboard. Then you can view the project files and refer to the sources of this commit, i.e.

http://github.com/jquery/jquery/blob/27291ff06ddb655f90a8d1eada71f7ac61499b12/src/css.js#L171-L185 .

Note that the only difference in the URL is to change the name of the branch name with a SHA commit.

+1 review from Paul Irish:

plus you only need 4 SHA characters in the url ... it turns out.
I usually truncate to 7 characters.

Nice: http://github.com/jquery/jquery/blob/27291ff/src/css.js#L171-185


If you have a GitHub page that does not link to sha1, type y :
which will reload the same page with the current SHA1 .

+14
source share

If you go to a file (or the version of the file you want to access), click the line number (or hold down the shift key to select a range).

=> you will see that the URL has changed (it adds something like #L21-L23 to the URL).

Just copy the url.

+3
source share

All Articles