117

Given a GitHub repository, how can I quickly find the date of its first commit?

I often want to know how old the project is, but I cannot find a quick way to get to the start of the commit histories for projects with very long commit histories.

1

13 Answers 13

128

Click on the "Insights" tab of the repository for which you want to see the oldest commit, followed by the "Network" sub-tab on the left menu bar. When the page is fully loaded (i.e. you can see lots of lines joining and all), press Shift+ to go all the way to the first commit. Click on the dot that represents the first commit and you can get it.

Note: This only works for repositories that were created on GitHub originally, not repositories that were imported from another place (i.e. commits not registered through GitHub itself). Also, this method may not necessarily work if the repository has too many forks.

0
33

Hydra's answer may not work with projects that have a lot of forks: "Couldn't load network graph. Too many forks to display."

You can check the 'Contributors' tab under 'Insights'

"Contributors" tab in "Insights"

4
  • 2
    If you select the very left edge of the graph using the brush, then click on the # commits for the first committer, you'll actually see the commits.
    – Gordon
    Commented Oct 18, 2016 at 12:20
  • @Gordon that is not very helpful, it just shows all commits for that person
    – Zombo
    Commented Nov 30, 2016 at 1:33
  • 1
    @StevenPenny, the question was just how to get the date of the first commit. Granted, it's messy, but if you select just the very left edge, you'll see the first commit. I prefer the dedicated site I linked in my answer below.
    – Gordon
    Commented Nov 30, 2016 at 1:49
  • Doesn't work if the default branch doesn't have the earliest commit.
    – OrangeDog
    Commented Dec 6, 2016 at 10:55
29

If you have cloned the repo, just use git commands as usual:

// cd to repo
$ git log --reverse

it will show you the history of commits in reverse order

2

This will get you the last page:

<?php
$s_url = $argv[1] . '/commits?page=';
$n_hi = 1;

while (true) {
   $s_hi = sprintf('%s%d', $s_url, $n_hi);
   echo $s_hi, "\t";
   $s_get = file_get_contents($s_hi);
   if (strpos($s_get, 'No commits found') !== false) {
      echo "Not Found\n";
      break;
   }
   echo "OK\n";
   $n_lo = $n_hi;
   $n_hi *= 2;
}

while (true) {
   $n_mid = intdiv($n_lo + $n_hi, 2);
   if ($n_mid == $n_lo) {
      break;
   }
   $s_mid = sprintf('%s%d', $s_url, $n_mid);
   echo $s_mid, "\t";
   $s_get = file_get_contents($s_mid);
   if (strpos($s_get, 'No commits found') !== false) {
      echo "Not Found\n";
      $n_hi = $n_mid;
   } else {
      echo "OK\n";
      $n_lo = $n_mid;
   }
}

Example:

PS C:\> git.php https://github.com/jp9000/OBS
https://github.com/jp9000/OBS/commits?page=1    OK
https://github.com/jp9000/OBS/commits?page=2    OK
https://github.com/jp9000/OBS/commits?page=4    OK
https://github.com/jp9000/OBS/commits?page=8    OK
https://github.com/jp9000/OBS/commits?page=16   OK
https://github.com/jp9000/OBS/commits?page=32   OK
https://github.com/jp9000/OBS/commits?page=64   OK
https://github.com/jp9000/OBS/commits?page=128  Not Found
https://github.com/jp9000/OBS/commits?page=96   Not Found
https://github.com/jp9000/OBS/commits?page=80   Not Found
https://github.com/jp9000/OBS/commits?page=72   OK
https://github.com/jp9000/OBS/commits?page=76   OK
https://github.com/jp9000/OBS/commits?page=78   OK
https://github.com/jp9000/OBS/commits?page=79   OK
1

You can use unix sed tool for filtering just the date of the first commit using

git log --reverse | sed -n -e "3,3p" 

I think it is exactly you need.

1

Get commit list reversed from repo URL (copy only repo index to temp dir, then delete):

#!/bin/bash

TMP_DIR=$(mktemp -d -t git-first-commit-date-XXXXXXXXXX)

REPO_URL="$1"
MAIN_BRANCH="$2"

if [[ -z "$REPO_URL" ]]; then
  echo "Error: no repo URL provided"
  exit 1
fi

if [[ -z "$MAIN_BRANCH" ]]; then
  MAIN_BRANCH="main"
fi

cd ${TMP_DIR}

set -x

git clone --filter=blob:none --no-checkout --single-branch --branch "$MAIN_BRANCH" "${REPO_URL}" .

git log --reverse

chmod -R u+w ${TMP_DIR}/.git
rm -r ${TMP_DIR}
1

A quick technique that worked for me was to just use curl with the GitHub API to determine the repo's creation date. It won't be as accurate as the first commit date for forks or other situations where the project was started before the repo was created (e.g. started on GitLab and then imported).

The syntax I used for this was: curl -s https://api.github.com/repos/[username]/[repository-name] | jq '.created_at'.

1

Further to @Igor-Parra's solution using git log --reverse, Git applies --reverse after any filtering of commits, and you should output --all commits and use other commands to restrict the output. You can use the formatting options to get the output you like.

Get just the date of the first commit

Using the %as format to display the author date in short format.

$ git log --reverse --format="format:%as" --all | head -n 1
2017-10-10
Get the date in ISO 8601 format of the first commit
$ git log --reverse --format="format:%aI" --all | head -n 1
2017-10-10T18:27:11+02:00
Get just the year of the first commit

By using %ad output format, the --date format is respected. And here we can use additional formatting %Y to select just the year.

$ git log --reverse --date="format:%Y" --format="format:%ad" | head -n 1
2017
Get more details of the first commit

Just select the 3 lines that summarize the commit details as git log does in the normal output.

$ git log --reverse --all | head -n 3
commit aa00aa00aa00aa00aa00aa00aa00aa00aa00aa00
Author: Name Surname <[email protected]>
Date:   Tue Oct 10 18:27:11 2017 +0200

Note that there is no need to reverse if you format and use other commands to filter the relevant commit. You could use tail instead of head for example. But a reversed list can be easier to work with if you need more details, like I show in my example to print the commit metadata.

Note that Git keeps track of both the 'author date' and the 'committer date'. The above commands use the author date %as but you can get the committer date by replacing the %a for %c like %cs. In the default 'medium' type git log output the 'author date' is shown.

1
  • this requires you to clone it. Most of the time I don't want to do that yet
    – Ooker
    Commented Sep 21 at 7:58
1
  1. Go to Commits page.
  2. From the date picker on the upper right side, click on year to open the drop-down list for it.
  3. Choose the oldest item in the list.
  4. Do the same for month.

The key is, Github only shows dates that there has been some commits. Thus this method should be able to get you to the oldest commit on the selected branch pretty quickly.

image of date picker on a repo active since 2018 image of date picker on a repo active since 2013

1
  • 5 months and no single upvote? Let me fix that
    – Ooker
    Commented Sep 21 at 8:04
0

Using GitHub's GraphQL API which is accessible here, we can do it with two different queries and a tiny bit of experimentation and searching.

In the first query, we get the creation date of the repo (which is usually handy in terms of knowing how old a repo is),

query { 
  repository(name: "go-ethereum", owner: "ethereum") {
    createdAt
  }
}

The reply (on the right hand side if using the Explorer) might be

{
  "data": {
    "repository": {
      "createdAt": "2013-12-26T13:05:46Z"
    }
  }
}

We have a candidate date. Next, we query the history of commits on main branch, and we can follow several strategies but I have found that viewing the history until the day after creation works well

query { 
  repository(name: "go-ethereum", owner: "ethereum") {
    createdAt
    defaultBranchRef {
        target{
        ... on Commit{
            history(until: "2013-12-27T00:00:00") {
            nodes {
              abbreviatedOid
              authoredDate
              committedDate
              message
            }
          }
        }
      }
    }
  }
}

The last commit included in the response reads

...
{
  "abbreviatedOid": "5db3335",
  "authoredDate": "2013-12-26T11:45:52Z",
  "committedDate": "2013-12-26T11:45:52Z",
  "message": "Initial commit"
}

We've found the date of the initial commit!

-2

There is a way to do it from the GitHub interface itself.

Go the the project page and pick the Code tab followed by the Commits sub-tab as shown here:

enter image description here

That brings you to your list of commits. If you then scroll to the bottom of the page, you can keep going back in time by clicking the Older button.

I couldn't really find a way to sort it so that the commits shown in ascending order.

1
  • 10
    I already knew that. The question was for projects with very long commit histories.
    – Randomblue
    Commented May 3, 2013 at 7:35
-2

None of the solutions listed above worked for me. git log --reverse does not work if there are a lot of forks in your tree. The script mentioned by @steven-penny did not work because github changed their urls to use a hash for the after query param value when browsing commints /master?after=Y3Vyc29yOvqNPhkVDBdTgRaxBYnOx1jBe88LKzM0 and neither did any of the graphs for the repo.

So what did work for me was quite simple. gitk. Using gitk and scrolling down to the last commit gave me the information I was looking.

Hope this helps other folks looking for similar info.

-3
git log --reverse --format="format:%ci" | sed -n 1p

If you want to get it from a command line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.