Linking to the newest version of a file on GitHub
Something I was trying to do over the weekend, but couldn’t work out, was to construct a link to the latest/newest/most recent version of a file—what some other version control systems refer to as HEAD—on GitHub. I couldn’t do it, and the people I asked didn’t know how to either.
Today, I worked it out: just replace the commit hash with the branch name. It makes sense when you think about it, but my knowledge of git wasn’t deep enough to allow me to make that leap.
So, for example, this link to the raw version of a particular commit (newlines added for formatting)
http://github.com/threedaymonk/ons_graph /raw/0a02f7c80b0b69a6d83f15964af4a2a97c15ddf8 /ons_graphs.user.js
becomes
http://github.com/threedaymonk/ons_graphs /raw/master/ons_graphs.user.js
Or, to put it another way:
http://github.com/<user>/<project>/raw/<branch>/<path to file>
It’s easy when you know how, isn’t it?