302

Is there an easy way to navigate to the earliest commit of a large open-source project in GitHub?

The project has over 13,000 commits as of today. I don't want to press the "Older" button on the commit history page hundreds and hundreds of times to get to the initial commit (or first commit).

hashim
  • 55
  • 7
jdw
  • 3,755
  • 3
  • 17
  • 16

10 Answers10

277

There's no obvious UI to do this, but there is a way to construct the right URL to go to page one of the commit log.

Suppose we want to find the first commit of the dotnet/runtime repository. First take a note of the number of commits in the repository: it is currently 125,882. Now go to the list of commits (click on commit count), and click "Older" once. The URL will be something like this: https://github.com/dotnet/runtime/commits/main?after=2aec3816f9bbc0eda3261daa335a05ea0df31b9c+34

Notice the +34 part. That's how many commits are skipped. Change that to 125,882 minus 1 minus 35 per page, that gives us this URL, which takes you right to the first page of the dotnet/runtime commit history.

Roman Starkov
  • 59,298
  • 38
  • 251
  • 324
  • 23
    Nice, I created a bookmarklet to do this. https://github.com/bpceee/oldest – bpceee May 28 '18 at 09:40
  • That's neat, but it only works on public repos, not private ones, like the one I use at work. Still useful. – odigity Jul 01 '22 at 14:52
  • 2
    @odigity It works for private repos as well. – Spikatrix Aug 08 '22 at 04:50
  • @bpceee your bookmarklet worked a treat. For any mac/chrome users, command + shift + b brings up the bookmark bar that you have to drag the bookmarklet into (same again to get rid of it) – stevec Apr 16 '23 at 08:22
178

Clone the repository, open with the command line and run $ git log --reverse

This will show the commits in reverse order.

Then you can view it on github once you have the ID(Object Name) of the first commit ... something like... https://github.com/UserName/Repo/commit/6a5ace7b941120db5d2d50af6321770ddad4779e

Schmalzy
  • 17,044
  • 7
  • 46
  • 47
  • 9
    One tweak, I would add the `oneline` arg to this -- `git log --reverse --oneline` so that you can view it as a list – rynmrtn May 23 '17 at 12:52
  • 1
    And if you're using the Windows command prompt and want to avoid being sucked into Vim(?), use `git log --reverse --oneline | more`. Standard `more` behavior, Ctrl + C to quit. – Sinjai Dec 26 '18 at 22:50
  • is it me or does `--reverse` not play well with `-n` / `--max-count`? – jxramos May 26 '22 at 01:05
66

Feb. 2015: In GitHub, is there an easy way to navigate to the earliest commit of a large open source project?

Yes there now is! (Meaning: without cloning the repo, and applying git log in the local clone)

Since January 2017, you have "Navigate file history faster with improved blame view" on GitHub.

Whether you're debugging a regression or trying to understand how some code came to have its current shape, you'll often want to see what a file looked like before a particular change.
With improved blame view, you can easily see how any portion of your file has evolved over time without viewing the file's full history.

Here is a demo getting back to the original oldest commit of the git/git repo itself (47K+ commits)... in three clicks!

demo git/git

The trick here is to chose a file likely to be found in the first (or very early) commit, like a README.md.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 15
    This generally works, but it assumes that you know which files existed when the repo was created, and that you can find lines that haven't changed many times since inception. – Wilfred Hughes Jun 13 '17 at 14:08
  • 1
    @WilfredHughes I used this method for Go to jump back 32,986 commits to the [first commit](https://github.com/golang/go/commit/0bb0b61d6a85b2a1a33dcbc418089656f2754d32) which happens to be a fun easter egg. In this case, the readme didn't go back until the beginning, so I repeated the process by pressing `Browse files` and opening the blame for a different file. – thaliaarchi Jun 22 '17 at 06:25
  • @andrewarchi Nicely done. Actually the first few commits are easter-eggs: https://stackoverflow.com/a/21981037/6309 – VonC Jun 22 '17 at 06:31
  • I would consider this a "workaround" whereas the answer by @schmalzy is more direct. – Jimmy Bosse Aug 18 '17 at 12:53
  • @JimmyBosse It is *not* a workaround. It is the answer to the original question. A `git log` only works if you clone the (potentially huge) repo locally. If you want to "*navigate*" to the fist commit, then this is it. – VonC Aug 18 '17 at 12:56
  • Doing this on `.gitignore` file seems to speed up the flow as it does not change too much – Orkhan Alikhanov Aug 11 '19 at 17:37
23

On project page click tab Insights > Contributors. Select the beginning of the histogram. Click the commits number. Done.

Github Surfraw repository, with arrows pointing to the 2 steps: select-histogram-range and click-filtered-commits

PS - Draw a small range to get a single page.

Kamafeather
  • 8,663
  • 14
  • 69
  • 99
  • Please share more details. How do you navigate from that page to the first commit? – Nico Haase Nov 15 '21 at 12:53
  • 1
    You can do it pretty easily: **(1)** select the beginning of the histogram; in the popup **(2)** click on the commits number to show that chunk of history. – Draw a small range to get a single page. – Kamafeather Jan 13 '22 at 04:19
17

You can get to the first page of commits with the following, which I keep as a snippet in Chrome dev tools.

function githubFirstCommitsPage() {
  let el = document.querySelector('.repository-content');
  let commits = el.querySelector('[aria-label^=Commits]');
  let base = commits.closest('a').href;
  let count = commits.previousElementSibling
    .textContent
    .trim()
    .replace(/[^\d\.\-]/g, "");
  count = count-36;
  let sha = el
    .querySelector('[data-test-selector="commit-tease-commit-message"]')
    .href
    .split('/');
  sha = sha[sha.length-1];
  window.location = `${base}?after=${sha}+${count}`;   
}

githubFirstCommitsPage();
Michael
  • 637
  • 1
  • 7
  • 13
Michael Terry
  • 983
  • 11
  • 18
13

You can navigate to a GitHub repository's first commit using the init bookmarklet.

INIT

A bookmarklet to quickly get you to the first commit of a repo.

Overview

Being able to quickly navigate to the oldest commit in a repo is quite helpful. Go ahead and drag the bookmarklet (link) onto your bookmark bar and click it whenever you'd like to go to the first commit of a repo.

Usage

Go to any particular repo's landing page (e.g. like the one you're on) and click the bookmarklet, which will take you to the first page (initial commit). By default, it tracks the master branch, but if you change the branch on the landing page, it will go to that branch's first commit.

Retrieved from README.md on GitHub


Disclaimer: I contributed a small Readme update to init a few minutes before posting this answer.

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
11

You need to use the git log --reverse command of git.

This will return the history of commits for the specified repo in reverse order (oldest to newest).

Then, with the help of some sed magic, you could have something like the date of the first commit (which is what I've seen I've always needed for myself).

git log --reverse | sed -n 3p

Ultimately, you might want to automate this as well (, since it's mostly either boring to type the command or just impossible to remember it), so a shell script like this one might come to the rescue.

teobais
  • 2,820
  • 1
  • 24
  • 36
8

This link gives a UI way to do this on GitHub. Summary:

  1. 'Insights' tab

  2. Network tab (left side)

  3. Shift + <--

Josh Britton
  • 425
  • 4
  • 17
7

Another simple trick with UI only is to check the git history of the file .gitignore or README.md, 99% of cases, you will find quickly the first commit.

Xiang ZHU
  • 365
  • 2
  • 13
2

A very easy solution.

  1. Press command + shift + b to bring up the Bookmarks bar if using chrome
  2. Go here
  3. Drop and drag the word 'OLDEST' into the bookmarks bar
  4. Go to any GitHub repo, and click 'OLDEST' in your bookmarks bar
  5. It will automatically go to the oldest commit!

Source: thanks to @bpc333 for the awesome tool that makes it possible.

OR

Navigate to the commits page of a GitHub repo

Change 'main' in the code below to whatever the name of the branch is

(function(){(([_, repo, branch='main']) => {fetch(`https://github.com/${repo}/tree/${branch}`).then(res => res.text()).then(res => {let mainDocument = new DOMParser().parseFromString(res, 'text/html');let commitCount = mainDocument.evaluate('//span[@class="d-none d-sm-inline"]//strong', mainDocument.body).iterateNext().innerText;commitCount = Number(commitCount.trim().replaceAll(',', ''));let commitId = mainDocument.evaluate('//*[@class="f6 Link--secondary text-mono ml-2 d-none d-lg-inline"]', mainDocument.body).iterateNext().getAttribute("href").split('/').pop();let url = `https://github.com/${repo}/commits/${branch}?after=${commitId}+${commitCount-10}`;window.location = url;})})(window.location.pathname.match(/\/([^\/]+\/[^\/]+)(?:\/(?:tree|commits|blob)\/([^\/]+))?/))})()

Open the JS console with command + shift + j and paste it in and hit enter, it will navigate to the first commit on that branch.

This second method uses the same code as the first one, but without the bookmark.

stevec
  • 41,291
  • 27
  • 223
  • 311