Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get last commit date inside a folder/directory in github repo?

For example: I want to get a last commit date in here - https://github.com/elasticsearch/elasticsearch/tree/master/dev-tools/pmd

With this I can get into pmd folder - https://api.github.com/repos/elasticsearch/elasticsearch/contents/dev-tools/pmd

But this doesn't have any data about the dates. I tried https://api.github.com/repos/elasticsearch/elasticsearch/contents/dev-tools/pmd/commits and this returns me 'not found' message.

Tried the git url with sha - https://api.github.com/repos/elasticsearch/elasticsearch/git/blobs/58788337ae94dbeaac72a0901d778a629460c992 but even this doesn't return any helpful info.

How to get the date of the commit inside a folder using github-api?

like image 874
tech_human Avatar asked Sep 18 '14 20:09

tech_human


People also ask

How can I see last commit in github?

Viewing a list of the latest commits. If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.

Which command is used to see the last commit on each branch?

After you have created several commits, or if you have cloned a repository with an existing commit history, you'll probably want to look back to see what has happened. The most basic and powerful tool to do this is the git log command.

How can I see the code of a previous commit?

All that you have to do is go on to the file that you committed on and go to the history for it, then select the earliest commit with the <> icon to view the code at that time.


Video Answer


1 Answers

New answer using the GitHub API:

Request the commits that touched the subdirectory using GET /repos/:owner/:repo/commits, passing in the path argument that specifies the subdirectory in question:

path: string, Only commits containing this file path will be returned.

The response will be zero or more commits. Take the latest and look at its commit/author/date or commit/committer/date, depending on which you're looking for:

[
  {
    ...,
    "commit": {
      "author": {
        ...,
        "date": "2011-04-14T16:00:49Z"
      },
      "committer": {
        ...,
        "date": "2011-04-14T16:00:49Z"
      },
      ...,
    },
  },
]

Original answer using a local copy:

Try git log -n 1 --pretty=format:%cd path/to/directory. This will give you the committer date of the most recent commit in that directory.

You can also use these other date formats:

  • %cD: committer date, RFC2822 style
  • %cr: committer date, relative
  • %ct: committer date, UNIX timestamp
  • %ci: committer date, ISO 8601 format
  • %ad: author date (format respects --date= option)
  • %aD: author date, RFC2822 style
  • %ar: author date, relative
  • %at: author date, UNIX timestamp
  • %ai: author date, ISO 8601 format
like image 60
Chris Avatar answered Oct 12 '22 22:10

Chris