Senseful
Senseful

Reputation: 91881

How to link to a static version of a file in GitHub?

If I want to reference specific line numbers on GitHub, I can do so by finding the file on GitHub, and selecting the line numbers on the left.

I get a URL such as this:

https://github.com/apple/swift/blob/master/stdlib/public/core/Optional.swift#L190-L199

The problem is that this reference has /master/ in it, meaning that if the file ever changes, the lines it will highlight are probably not the ones that I intended to highlight. How can I get a static version of this file so that I can reference this exact code I'm referring to?

Upvotes: 0

Views: 64

Answers (1)

Senseful
Senseful

Reputation: 91881

Quick solution by modifying the URL:

  1. Scroll to the top of the page, and you'll see a SHA of the latest commit.

    enter image description here

  2. Replace master in the URL with the SHA; 6d1ae2a in this case:

    https://github.com/apple/swift/blob/6d1ae2a/stdlib/public/core/Optional.swift#L190-L199

Using only UI:

  1. Scroll to the top of the page, and you'll see a SHA of the latest commit. Click the SHA (6d1ae2a in this case).

    enter image description here

  2. Click "Browse files" on the top right.

    enter image description here

  3. Find the file again. Now instead of master, you'll see the SHA in the tree:

    enter image description here

  4. Highlight the lines as you did before and copy the URL:

    https://github.com/apple/swift/blob/6d1ae2a39c1b77240107854b0ae1a35800a8ba73/stdlib/public/core/Optional.swift#L190-L199

Upvotes: 1

Related Questions