How to navigate to the earliest commit in a repository?
GithubGithub Problem Overview
In GitHub, is there an easy way to navigate to the earliest commit of a large open source project?
The project has over 13,000 commits as of today. I don't want to have to press the "Older" button on the commit history page hundreds and hundreds of times to get to the initial commit (or first commit).
Github Solutions
Solution 1 - Github
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/coreclr repository. First take a note of the number of commits in the repository: it is currently 16,634. Now go to the list of commits, and click "Older" once. The URL will be something like this: https://github.com/dotnet/coreclr/commits/master?after=872095a758a3a6191a9798c94a98e8d1e16b2254+34
Notice the +34
part. That's how many commits are skipped. Change that to 16,634 minus 1 minus 35 per page, that gives us this URL, which takes you right to the first page of the coreclr commit history.
Solution 2 - Github
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
Solution 3 - Github
> 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!
The trick here is to chose a file likely to be found in the first (or very early) commit, like a README.md
.
Solution 4 - Github
I wanted to see one of the earliest commits of nodejs project. I have done the following.
- Visited the site nodejs. Then observed that the total number of commits is around twenty three thousand(23652 to be precise) at this point in time.
- Next I clicked on that commits link and that took me to https://github.com/nodejs/node/commits/master as shown below.
-
Now scrolled down to the bottom and I found Newer and Older buttons. The Newer button is disabled. I clicked the older button and it took me to https://github.com/nodejs/node/commits/master?after=de37ba34c5d6f3a2d18daf482f850be8fddb4621+34
-
Now observe that the url has +34. Now I changed that to 23000(since the number of commits I had observed is 23000). So the new url I tried is
https://github.com/nodejs/node/commits/master?after=de37ba34c5d6f3a2d18daf482f850be8fddb4621+23000
- Now I am almost there. With a few more iterations or by older button clicks I reached where I want.
Solution 5 - Github
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();
Solution 6 - Github
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.
Solution 7 - Github
On project page click tab Insights > Contributors
.
Select the beginning of the histogram.
Click the commits number.
Done.
PS - Draw a small range to get a single page.
Solution 8 - Github
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.
Solution 9 - Github
This link gives a UI way to do this on GitHub. Summary:
-
'Insights' tab
-
Network tab (left side)
-
Shift + <--