How to press ‘y’ to navigate to the permalink for a file’s exact commit ID on GitHub.com – 052

Suppose you had a question about the contents of a file at an exact moment in time (or in git-speak: at an exact commit in time). If you were to visit the repo and navigate directly either to a file or the line in question in a file, e.g. https://github.com/saraford/your-moment-of-github-zen/blob/master/main.js#L74 showing the line

mainWindow.webContents.openDevTools();

you might forget or not even realize (like me) that you’re copying the link for the latest version of that file on master (or in git-speak: the version of the file at the current head of master).

In other words, if someone were to come along and make a change to this file, your link to this line of code at the latest commit on master might be a link to a totally different line of code instead of the openDevTools() link.

Press the `y` key and you’ll see that the page seems to refresh. Well, yes and no. The page has updated, but look at the URL now.

https://github.com/saraford/your-moment-of-github-zen/blob/f06f035cfed7c0ea05db8bd3cc25b22c43cea6d7/main.js#L74

now you got the permalink to that exact line of code!

This shortcut is the functional equivalent of clicking Code – Commit – Browse the repository at this point in the history – clicking the file (e.g. main.js) – and then clicking the line number.

This shortcut works for any branch name, specific commit SHAs, and tags, according to the docs. E.g. suppose you were looking at main.js on a branch called windows-fix located at https://github.com/saraford-tips/your-moment-of-github-zen/blob/windows-fix/main.js and you pressed the `y` key. The URL would change to https://github.com/saraford-tips/your-moment-of-github-zen/blob/811aacbd492044c8a02536129edf42862d0a593d/main.js

I hate not having a photo to go alongside a tip, so here’s a picture of a Great Dane next to a small (terrier?) dog, aka how I feel standing next to tall people.

Great Dane standing next to small dog

photo taken from https://flic.kr/p/b4RGX8

One thought on “How to press ‘y’ to navigate to the permalink for a file’s exact commit ID on GitHub.com – 052

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s