3

How many of you ever clicked on a Github link to a file version, just to find out that who made the link didn't care of putting a fixed commit sha (or, protip: simply pressing Y) when copying it from Github, and that the link is expired because now the master branch points to a different commit that at the time when the link was made, and the file was moved and changed in the meanwhile?

✋‍♀️‍♀️‍♂️‍♂️

I see... So is there any Github url parameter or a way to specify the branch path, that would allow me to display the version of the branch at a specific time in the past?

Somethinge like https://github.com/repo/master/old/path/to/file?date=2019-07-31T00:15:43+00:00.

The alternative is to find out the date from the, let's say, Github issue's comment where you copied/clicked the link from and start to scroll through the branch's Commits pagination, until (almost at the last page..) you finally find the most recent commit closer to the date you found, so you can start to Browse files for the commit just found in order to get, after wasting 10/15 minutes, at the version of the file that the initial link author intended to actually lead to.

Or you need to ask an answer on SO. Not really convenient.

Is there such a parameter supported by Github?

Kamafeather
  • 8,663
  • 14
  • 69
  • 99
  • 1
    P? I though it was Y... https://help.github.com/en/articles/keyboard-shortcuts#source-code-browsing – VonC Jul 31 '19 at 04:59
  • @VonC you are right, my bad, I remembered wrong. Fixed, thanks :) – Kamafeather Jul 31 '19 at 12:42
  • Does this answer your question? [GitHub - Repository state at specified time](https://stackoverflow.com/questions/21345787/github-repository-state-at-specified-time) – August Janse Jan 20 '23 at 11:05

1 Answers1

1

You could make a curl, using the GitHub API, in order to list commits.

That particular API (GET /repos/:owner/:repo/commits) has a until parameter:

Only commits before this date will be returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.

The first commit listed would be the one you are looking for.
You can see examples here and here.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250