top | item 8046710

Don't link to line numbers in GitHub

230 points| xkarga00 | 11 years ago |andrew.yurisich.com | reply

58 comments

order
[+] joliss|11 years ago|reply
ProTip: Hit the y key on any GitHub page with source code.

It'll instantly expand the URL to its canonical form, e.g.

https://github.com/sass/libsass/blob/master/parser.cpp#L29-L...

to

https://github.com/sass/libsass/blob/fca1f75a14fe5336c7b1a4b...

which stays valid indefinitely (unless the commit is deleted from the repo).

P.S. Hit the ? key for more keyboard awesomeness. :)

[+] mapleoin|11 years ago|reply
Yeah, that's what he said in the post.
[+] kmike84|11 years ago|reply
Thanks! It was a pain. Especially if you've moved from Bitbucket where "stable" links to line numbers are default.
[+] tieTYT|11 years ago|reply
Why doesn't the URL look how it would look if you hit y by default? Seems like that would be what you usually want.

When I send someone a link, it's because I want them to see what I'm looking at.

[+] enesunal|11 years ago|reply
Another reason to love github, thanks.
[+] wereHamster|11 years ago|reply
"Don't Link that Line Number!" -> "Don't use unstable references if you need stable ones"
[+] DougBTX|11 years ago|reply
Yea, unnecessarily controversial title. The point is that if you want to link to some code, link to a particular version of that code, not the latest version of that code. The whole file could be deleted, let alone a change in line position.
[+] 32bitkid|11 years ago|reply
I had the same realization a while ago, even started working on a documentation engine built around the idea that I never quite finished:

https://github.com/32bitkid/zang

The general concept was a markdown preprocessor that would include references to commits in git repositories and expand to the referenced content.

Because all the references were bound to a commit, then a) they were stable (if you used a hash rather than brach name), but more importantly b) you could determine when the file had changed and the documentation was possibly out of date.

it would generate a warning/error and one would have to update the documentation accordingly.

Anyway nice to see other people with the same underlying idea.

[+] sqs|11 years ago|reply
Or link directly to functions on Sourcegraph, if you are referring to a function and not just a line range.

Like https://sourcegraph.com/code.google.com/p/go/.GoPackage/net/....

(Full disclosure: I'm one of the creators of Sourcegraph.)

[+] patrickg|11 years ago|reply
I really begin to like sourcegraph, nice job! I don't know how to ask the question without sounding too negative: any chance it might get faster? I took about 10 seconds (just a feeling, didn't measure it) to load the page.
[+] potomak|11 years ago|reply
I totally agree. The problem is not links to line numbers, that I found really useful, the problem is that these links must have a commit context otherwise they become unreliable.
[+] bjeanes|11 years ago|reply
> Then, tap the "y" key to jump to the last commit found for that region.

That's not actually what happens. Pressing "y" resolves the current reference (master, some tag, whatever). It has nothing to do with what you select, you're just following the pointer that is the current ref.

[+] jrochkind1|11 years ago|reply
You can of course link to a line number on a specific commit. You don't need to avoid line numbers, you just need to link to a specific commit.

The y shortcut is super helpful though -- I was always trying to figure out how to get the the latest commit hash on my own before, clicking on the latest commit in history etc., very cumbersome.

This is important enough for linking to sourcecode (I agree), that I kind of wish github had an actual button for it on screen, instead of having to know the magic shortcut. But I realize github screen real estate is precious.

[+] jbert|11 years ago|reply
Is there a reasonable use case for linking to line-numbers on branch/tag on github? If not, it might be good UX to remove that option. i.e. only honour such links to immutable urls.

Further, even if you're looking at a mutable reference (like master), the line number links could/should be to the underlying immutable url (based on the commit).

If there is a marginal use case for linking to line numbers of mutable refs, perhaps it should be the non-default case, discoverable by keyboard shortcut like this...

[+] warp|11 years ago|reply
Yes, in a team working remotely it is often useful to link to a specific chunk of code during a (voice or chat) conversation. Typically you're talking about the current code in a branch, and it is useful for the person clicking the link to know that we are in fact talking about HEAD and not a specific commit.

This is the equivalent of calling someone to your desk and pointing at the screen. It is fine if those links stop working a few hours later.

[+] augustl|11 years ago|reply
Good point, it would make sense to disable the feature for mutable references like "master".
[+] mtdewcmu|11 years ago|reply
Linking to line numbers is practically using goto, which is a coding faux pas. I'm sure they must be on the way out.
[+] jmileham|11 years ago|reply
This works great unless you're rebasing and the commit hash you reference falls out of use. In PR comments that I expect to rebase again before release but for which I don't expect changes earlier in the file I'm referencing, I often live on the edge and link to the mutable diff. In the context of PR comments, you can edit them after the fact, so neither choice is necessarily game over - you can fix the line number or the commit hash you point to after the fact.
[+] albertzeyer|11 years ago|reply
I often wished that I could link to function names or so instead.
[+] pjtr|11 years ago|reply
In Trac you can link to #/searchterm.
[+] nathell|11 years ago|reply
I've always linked to line numbers under specific commits or tags. Didn't know about the 'y' shortcut though, very helpful.
[+] adamwong246|11 years ago|reply
That's easy to fix- link to a line in a specific commit. Assuming you never clobber the history, that link should remain constant.
[+] ttty|11 years ago|reply
Anyone with minimal knowledge of github would know that the references can changes...
[+] ad_hominem|11 years ago|reply
This has nothing to do with line numbers whatsoever, it's about constructing links using whatever commit the branch is currently on rather than linking to the branch. A regular link to a file using a branch reference could just as easily disappear completely as the branch reference moves.
[+] trebor|11 years ago|reply
Please don't mention that you flagged the OP. That's against the guidelines: If you flag something, please don't also comment that you did.
[+] bttf|11 years ago|reply
Short but informative
[+] fjcaetano|11 years ago|reply
Someone just discovered space-time
[+] WorldWideWayne|11 years ago|reply
Why change the title to "Don't link to line numbers in GitHub", when that's not what the article is saying at all?
[+] danneu|11 years ago|reply
The original title is "Don't Link that Line Number" which also isn't what the article is saying, so the HN re-title is an improvement.

An accurate title would look more like "Use commit-specific links when linking to line numbers on Github".