Skip to content

Latest commit

 

History

History
132 lines (115 loc) · 3.77 KB

2010-04-23-commits.markdown

File metadata and controls

132 lines (115 loc) · 3.77 KB
layout title
default
Commits API

Commits API

Listing Commits on a Branch

commits/list/:user_id/:repository/:branch

An example of getting a listing of commits for a branch, we will get the latest commits on the 'master' branch of the Grit project.

$ curl http://github.com/api/v2/json/commits/list/mojombo/grit/master
{
  "commits": [
    {
      "parents": [
        {
          "id": "e3be659a93ce0de359dd3e5c3b3b42ab53029065"
        }
      ],
      "author": {
        "name": "Ryan Tomayko",
        "login": "rtomayko",
        "email": "rtomayko@gmail.com"
      },
      "url": "/mojombo/grit/commit/6b7dff52aad33df4bfc0c0eaa88922fe1d1cd43b",
      "id": "6b7dff52aad33df4bfc0c0eaa88922fe1d1cd43b",
      "committed_date": "2010-12-09T13:50:17-08:00",
      "authored_date": "2010-12-09T13:50:17-08:00",
      "message": "update History.txt with bug fix merges",
      "tree": "a6a09ebb4ca4b1461a0ce9ee1a5b2aefe0045d5f",
      "committer": {
        "name": "Ryan Tomayko",
        "login": "rtomayko",
        "email": "rtomayko@gmail.com"
      }
    }
  ]
}

Usually commits are a lot. That's why the API call doesn't return them all at once, but rather page by page. If you are after the whole list and not just the latest commits, you should add a ?page=N at the end of the API call incrementing the page number until you get no results. For example:

$ curl http://github.com/api/v2/json/commits/list/mojombo/grit/master?page=1
$ curl http://github.com/api/v2/json/commits/list/mojombo/grit/master?page=2
...
$ curl http://github.com/api/v2/json/commits/list/mojombo/grit/master?page=N

Listing Commits for a File

commits/list/:user_id/:repository/:branch/*path

An example of using this to get all the commits that modified the gemspec file for the Grit project would be:

$ curl http://github.com/api/v2/json/commits/list/mojombo/grit/master/grit.gemspec
{
"commits": [
  {
    "parents": [
      {
        "id": "9f2d86b941c4aeccc1125fe2864e3aba126fd997"
      }
    ],
    "author": {
      "name": "Tom Preston-Werner",
      "login": "mojombo",
      "email": "tom@mojombo.com"
    },
    "url": "/mojombo/grit/commit/b8a3d3b374630ba94cd1efab13a2eceadf8d2bf4",
    "id": "b8a3d3b374630ba94cd1efab13a2eceadf8d2bf4",
    "committed_date": "2010-09-29T13:46:45-07:00",
    "authored_date": "2010-09-29T13:46:45-07:00",
    "message": "Release 2.3.0",
    "tree": "bd73ef982d782d06f5ae19b5276eaa535e18c1a3",
    "committer": {
      "name": "Tom Preston-Werner",
      "login": "mojombo",
      "email": "tom@mojombo.com"
    }
  }
]
}

Showing a Specific Commit

commits/show/:user_id/:repository/:sha

An example of using this to get a the changes introduced on a specific commit in the Grit project would be

$ curl http://github.com/api/v2/json/commits/show/mojombo/grit/5071bf9fbfb81778c456d62e111440fdc776f76c | jsonpretty
{
  "commit": {
    "message": "Version bump to 1.1.1",
    "added": [

    ],
    "removed": [

    ],
    "parents": [
      {
        "id": "05372bffe2b60b0d1802f338551856221e0a89d2"
      }
    ],
    "modified": [
      {
        "diff": "@@ -1,4 +1,4 @@\n --- \n :major: 1\n :minor: 1\n-:patch: 0\n+:patch: 1",
        "filename": "VERSION.yml"
      }
    ],
    "author": {
      "name": "Tom Preston-Werner",
      "email": "tom@mojombo.com"
    },
    "url": "http:\/\/github.com\/mojombo\/grit\/commit\/5071bf9fbfb81778c456d62e111440fdc776f76c",
    "id": "5071bf9fbfb81778c456d62e111440fdc776f76c",
    "committed_date": "2009-03-31T09:54:40-07:00",
    "authored_date": "2009-03-31T09:54:40-07:00",
    "tree": "e5b860cb18c5c334e480993ca4549d13e0f8b1a8",
    "committer": {
      "name": "Tom Preston-Werner",
      "email": "tom@mojombo.com"
    }
  }
}