Show HN: First Commit – find the first commit of any GitHub project
first-commit.com
first-commit.com
Now, it's like: "Uh, oh, this initial checkin better be perfect. Someone will scrutinize it with first-commit."
OTOH, no one has ever expressed any interest whatsoever in any of my GitHub repos. I doubt even first-commit can change that.
1. It's slightly harder to edit the first commit afterwards (say, to replace a working title with the actual project title before publishing, or to fix authorship or whatever).
2. I create a lot of small repos, all the time, so I have a shell alias for "init, commit, add .gitignore, commit".
[1] git init && git commit --allow-empty -m 'Initial commit'
git init && git commit --allow-empty -m "$(basename (readlink -f .))" pwd -P
would be equivalent and more portable (POSIX compliant[1]) than readlink -f .
which doesn't work on BSD-based systems.[1]: http://pubs.opengroup.org/onlinepubs/009696899/utilities/pwd...
https://github.com/golang/go/commits/master?page=727
EDIT: I just noticed that they're labeled as being by Brian Kernighan. What?
EDIT2: Oh, it's his original hello world code: https://en.wikipedia.org/wiki/%22Hello,_World!%22_program What's it doing there? Just for novelty's sake?
Here's one of my repos: http://first-commit.com/davidgiven/ack
First checkin 1984. That's real history, too; those files, or their descendants, are still in the current snapshot. Incidentally, not only does that commit predate git, or the SVN repository I converted it from, but it predates CVS itself... I've seen suggestions that the pile of shell scripts which became CVS was actually written for that project!
Not my code, I should add, I'm just looking after it. It's Andy Tanenbaum and Cerial Jacobs' compiler toolchain, the Amsterdam Compiler Kit. Portable, platform independent ANSI & K&R C, Pascal, Modula-2, Occam and Algol-68 development kit, complete with linkers, assemblers and libc...
(also -- using "would have had to have" is such a silly thing, but i love it every time)
Repo: https://github.com/FarhadG/init Demo: http://farhadg.github.io/init/landing/
I could add the functionality to determine which branch does actually have the oldest commit, but I find it more intuitive and useful to go the first commit of the current branch that you're on...
Thanks for the feedback.
Why is this tool interesting? Or, why is this tool useful?
Wasn't this already pretty easy to find if one was so inclined?
Sure, you can click older a bunch of times but it doesn't seem like there's a button to jump to the last page of commits. I guess you could clone the repo and look yourself using git log but this can be something of a hassle and probably wouldn't always be possible depending on the device (I'm thinking mobile devices, tablets etc).
You could probably guess a large page number, use it in the commit history URL and chop it in half repeatedly until you don't get a 404 and then repeat from there to try and find the last page of commits. Ultimately this is an issue with how GitHub's commit history is designed though.
Just do something like:
git rev-list --max-parents=0 HEAD'git rev-list' will give you the SHA-1 hashes of all the commits reachable from a given commit. So 'git rev-list HEAD' is going to give you all commits reachable from HEAD, i.e. your latest one all the way to your first commit. After that, there's a bunch of ways you could filter that. For example, you could run 'git rev-list HEAD | tail -1' to get the hash of the first commit, and now all you need to do to show the whole diff is pipe it to 'xargs git show' (xargs reads from stdin and uses that as the argument to whatever comes after it.
The grandparent comment uses a slightly interesting trick – he/she used the built-in '--max-parents' filter. '--max-parents' limits the number of parent commits. For example, a merge has 2 or more parent commits, so the '--max-parents=1' option will exclude all merge commits. What commit has no parents? Why, the first commit of the repo, of course.
Hence, the command 'git rev-list --max-parents=0 HEAD | xargs git show'.
Personally, I would have used `master` instead of `HEAD` because any commit in git can be checked out, but `master` is highly likely to be the main line of development and thus be descended from the true first commit of the repository.
Here is an example of how you can quickly identify the first commits
You basically scroll the chart to the furthest left.
[1] - https://github.com/git/git/commit/e83c5163316f89bfbde7d9ab23...
couldn't resist =)
https://github.com/darktable-org/darktable
It appears to be the hyphen in the org name.
Seems like you don't handle commits by users not recognized by github.
git rev-list --max-parents=0 HEAD | xargs git showAnyways, I did a quick look at the source file[1] and it looks like it depends on the assumption of github returning 35 commit titles per page. From that, it divides total # of commits by 35 to derive the url for the last page containing the 1st commit. (The url you'd arrive at if you if you repeatedly clicked the "Older" button on github to get to the final page which contains the 1st commit.) It then scrapes that url for relevant data. (It uses the cheerio library to help with scraping.)
I'm not familiar enough with github's HTML navigation and page formatting to know if this method is fragile or robust. Github does offer an API[2] so it may be possible to get the 1st commit that way instead of scraping HTML that was intended for display in a web browser.
Excerpt of the arithmetic:
function getFirstPageUrl(repo, num_of_commits) {
const COMMITS_PER_PAGE = 35;
var first_page = Math.ceil(num_of_commits / COMMITS_PER_PAGE);
return `${BASE_URL}/${repo}/commits?page=${first_page}`;
}
[1]https://github.com/wong2/first-commit/blob/master/app/github...