Ronnie Overby
Ronnie Overby

Reputation: 46480

How to view github pages at specific commit?

I'm trying to view the documentation of a repository at a specific point in time. Is the github pages url hackable enough that I can specific a specific commit hash?

I can't seem to find any information on the web about this.

Upvotes: 19

Views: 4868

Answers (5)

trusktr
trusktr

Reputation: 45494

Instead of GitHub Pages, you can use raw.githack.com, which will allow you to use GitHub's Raw file server to view your files. For example, given a URL like this in my project:

https://github.com/lume/lume/blob/develop/examples/fbx-model.html

I can paste that into raw.githack.com and it will give me a URL like this:

https://rawcdn.githack.com/lume/lume/64303f70d55a4f25198b0a3130afc50450eef8c0/examples/fbx-model.html

Note that the URL has the latest commit hash in it. You should see a 3D model like this:

enter image description here

What raw.githack does is simply proxies to the GitHub files, but sets the correct mime types so that the browser will execute the files properly. Otherwise, GitHub's raw files (for example when you click on the "Raw" button to view a file raw) sends back text/plain instead of application/javascript mime types for JavaScript files. For example when viewing this file on GitHub,

https://github.com/lume/lume/blob/64303f70d55a4f25198b0a3130afc50450eef8c0/examples/fbx-model.html

if we click the "Raw" button it will take us to this:

https://raw.githubusercontent.com/lume/lume/64303f70d55a4f25198b0a3130afc50450eef8c0/examples/fbx-model.html

However you will not be able to view that file due to incorrect mime types, and instead the browser will simply show the text instead of rendering the page.

raw.githack proxies to those same files, but puts the correct mime types in the Content-Type header fields.

The cool thing is, you can simply push to your repo, and view the latest result without GitHub Pages! For example using a branch name:

https://raw.githack.com/lume/lume/develop/examples/fbx-model.html

You can replace the branch name with any git ref. The format is this:

https://raw.githack.com/<username>/<repo>/<ref>/<pathToFile>

For example, here's an example from gregmann's twgl.js repo at a particular commit:

https://rawcdn.githack.com/greggman/twgl.js/941d482b3de79741610e29478f16c85219fbeae6/examples/3d-texture-volume.html

The difference between raw.githack.com and rawcdn.githack.com is that any URLs on raw.githack.com have a cache that expires after a few minutes (useful for branches), whereas rawcdn.githack.com is cached permanently for production (useful for commit hashes).

Upvotes: 0

mindlessgreen
mindlessgreen

Reputation: 12132

I am also unable to find an ideal solution. What I do at the moment is to have subdirectories under the branch gh-pages named for example, v1,v2 etc. Then they are accessible as

org.github.io/repo/v1/
org.github.io/repo/v2/
...

This works, but there is almost 100% duplication of content with every version upgrade.

Upvotes: 0

Polygnome
Polygnome

Reputation: 7820

No, you can't. GitHub pages only serves the current content of the gh-pages branch.

You can, however, clone the repo and check out the commit you are looking for locally. You might have to run Jekyll locallly, though, since ts possible to not have the actual HTML files in the gh-pages branch, but a corrrectly set up jekyll page which will get converted by GitHub on-the-fly.

Upvotes: 3

damio
damio

Reputation: 6301

It's not possible via the url but you can always clone the repo and generate the doc yourself at the commit you want.

Upvotes: 0

David Jacquel
David Jacquel

Reputation: 52829

Once you push your gh-pages branch, old files are replaced by new ones on the static files server. Only one Jekyll build snapshot allowed.

Upvotes: 9

Related Questions