Let's say I'm on a GitHub page for a file in a repository, like so:
https://github.com/apple/swift/blob/master/stdlib/public/SwiftShims/HeapObject.h#L33
Note that this links to line 33
and branch master
. If I want to reference this is in an issue or pull request, I'd want a link to the current commit, so that updates to the file don't invalidate my link.
Is there a one-click way to do this?
Obviously, I can click on the commit at the top, copy the SHA, and paste it over master
, but that's inconvenient.
Best Answer
Here's a bookmarklet that can grab the commit URL for you. Just copy the code below into a bookmark in your browser, then when you're viewing a page like the one you linked to above, click the bookmark. A box will appear at the bottom of the screen like this one, containing the URL for the commit page:
Press CTRLC to copy the link (which will already be highlighted) and from there you can paste it wherever you need it.
Make sure that when you copy the code into a bookmark that
javascript:
appears at the beginning. (In some browsers, it doesn't always copy over.)