Github API

Getting access, Developing, Testing

Back to Github

Compare two commits

Compares two commits against one another. You can compare branches in the same repository, or you can compare branches that exist in different repositories within the same repository network, including fork branches. For more information about how to view a repository's network, see "Understanding connections between repositories."

This endpoint is equivalent to running the git log BASE..HEAD command, but it returns commits in a different order. The git log BASE..HEAD command returns commits in reverse chronological order, whereas the API returns commits in chronological order. You can pass the appropriate media type to fetch diff and patch formats.

The API response includes details about the files that were changed between the two commits. This includes the status of the change (if a file was added, removed, modified, or renamed), and details of the change itself. For example, files with a renamed status have a previous_filename field showing the previous filename of the file, and files with a modified status have a patch field showing the changes made to the file.

When calling this endpoint without any paging parameter (per_page or page), the returned list is limited to 250 commits, and the last commit in the list is the most recent of the entire comparison.

Working with large comparisons

To process a response with a large number of commits, use a query parameter (per_page or page) to paginate the results. When using pagination:

  • The list of changed files is only shown on the first page of results, but it includes all changed files for the entire comparison.
  • The results are returned in chronological order, but the last commit in the returned list may not be the most recent one in the entire set if there are more pages of results.

For more information on working with pagination, see "Using pagination in the REST API."

Signature verification object

The response will include a verification object that describes the result of verifying the commit's signature. The verification object includes the following fields:

| Name | Type | Description | | ---- | ---- | ----------- | | verified | boolean | Indicates whether GitHub considers the signature in this commit to be verified. | | reason | string | The reason for verified value. Possible values and their meanings are enumerated in table below. | | signature | string | The signature that was extracted from the commit. | | payload | string | The value that was signed. |

These are the possible values for reason in the verification object:

| Value | Description | | ----- | ----------- | | expired_key | The key that made the signature is expired. | | not_signing_key | The "signing" flag is not among the usage flags in the GPG key that made the signature. | | gpgverify_error | There was an error communicating with the signature verification service. | | gpgverify_unavailable | The signature verification service is currently unavailable. | | unsigned | The object does not include a signature. | | unknown_signature_type | A non-PGP signature was found in the commit. | | no_user | No user was associated with the committer email address in the commit. | | unverified_email | The committer email address in the commit was associated with a user, but the email address is not verified on their account. | | bad_email | The committer email address in the commit is not included in the identities of the PGP key that made the signature. | | unknown_key | The key that made the signature has not been registered with any user's account. | | malformed_signature | There was an error parsing the signature. | | invalid | The signature could not be cryptographically verified using the key whose key-id was found in the signature. | | valid | None of the above errors applied, so the signature is considered to be verified. |

Input

type: object properties: parameters: type: object properties: owner: type: string description: The account owner of the repository. The name is not case sensitive. repo: type: string description: The name of the repository. The name is not case sensitive. page: type: integer default: 1 description: Page number of the results to fetch. per_page: type: integer default: 30 description: The number of results per page (max 100). basehead: type: string description: >- The base branch and head branch to compare. This parameter expects the format `BASE...HEAD`. Both must be branch names in `repo`. To compare with a branch that exists in a different repository in the same network as `repo`, the `basehead` parameter expects the format `USERNAME:BASE...USERNAME:HEAD`. required: - owner - repo - basehead title: Parameters

Output

type: object title: Commit Comparison properties: url: type: string format: uri example: https://api.github.com/repos/octocat/Hello-World/compare/master...topic html_url: type: string format: uri example: https://github.com/octocat/Hello-World/compare/master...topic permalink_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/compare/octocat:bbcd538c8e72b8c175046e27cc8f907076331401...octocat:0328041d1152db8ae77652d1618a02e57f745f17 diff_url: type: string format: uri example: https://github.com/octocat/Hello-World/compare/master...topic.diff patch_url: type: string format: uri example: https://github.com/octocat/Hello-World/compare/master...topic.patch base_commit: type: object title: Commit properties: url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e sha: type: string example: 6dcb09b5b57875f334f61aebed695e2e4193db5e node_id: type: string example: MDY6Q29tbWl0NmRjYjA5YjViNTc4NzVmMzM0ZjYxYWViZWQ2OTVlMmU0MTkzZGI1ZQ== html_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e comments_url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments commit: type: object properties: url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e author: type: object title: Git User properties: name: type: string example: '"Chris Wanstrath"' email: type: string example: '"[email protected]"' date: type: string example: '"2007-10-29T02:42:39.000-07:00"' committer: type: object title: Git User properties: name: type: string example: '"Chris Wanstrath"' email: type: string example: '"[email protected]"' date: type: string example: '"2007-10-29T02:42:39.000-07:00"' message: type: string example: Fix all the bugs comment_count: type: integer example: 0 tree: type: object properties: sha: type: string example: 827efc6d56897b048c772eb4087f854f46256132 url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/tree/827efc6d56897b048c772eb4087f854f46256132 verification: type: object title: Verification properties: verified: type: boolean reason: type: string payload: type: string nullable: true signature: type: string nullable: true author: type: object title: Simple User properties: name: nullable: true type: string email: nullable: true type: string login: type: string example: octocat id: type: integer example: 1 node_id: type: string example: MDQ6VXNlcjE= avatar_url: type: string format: uri example: https://github.com/images/error/octocat_happy.gif gravatar_id: type: string example: 41d064eb2195891e12d0413f63227ea7 nullable: true url: type: string format: uri example: https://api.github.com/users/octocat html_url: type: string format: uri example: https://github.com/octocat followers_url: type: string format: uri example: https://api.github.com/users/octocat/followers following_url: type: string example: https://api.github.com/users/octocat/following{/other_user} gists_url: type: string example: https://api.github.com/users/octocat/gists{/gist_id} starred_url: type: string example: https://api.github.com/users/octocat/starred{/owner}{/repo} subscriptions_url: type: string format: uri example: https://api.github.com/users/octocat/subscriptions organizations_url: type: string format: uri example: https://api.github.com/users/octocat/orgs repos_url: type: string format: uri example: https://api.github.com/users/octocat/repos events_url: type: string example: https://api.github.com/users/octocat/events{/privacy} received_events_url: type: string format: uri example: https://api.github.com/users/octocat/received_events type: type: string example: User site_admin: type: boolean starred_at: type: string example: '"2020-07-09T00:17:55Z"' committer: type: object title: Simple User properties: name: nullable: true type: string email: nullable: true type: string login: type: string example: octocat id: type: integer example: 1 node_id: type: string example: MDQ6VXNlcjE= avatar_url: type: string format: uri example: https://github.com/images/error/octocat_happy.gif gravatar_id: type: string example: 41d064eb2195891e12d0413f63227ea7 nullable: true url: type: string format: uri example: https://api.github.com/users/octocat html_url: type: string format: uri example: https://github.com/octocat followers_url: type: string format: uri example: https://api.github.com/users/octocat/followers following_url: type: string example: https://api.github.com/users/octocat/following{/other_user} gists_url: type: string example: https://api.github.com/users/octocat/gists{/gist_id} starred_url: type: string example: https://api.github.com/users/octocat/starred{/owner}{/repo} subscriptions_url: type: string format: uri example: https://api.github.com/users/octocat/subscriptions organizations_url: type: string format: uri example: https://api.github.com/users/octocat/orgs repos_url: type: string format: uri example: https://api.github.com/users/octocat/repos events_url: type: string example: https://api.github.com/users/octocat/events{/privacy} received_events_url: type: string format: uri example: https://api.github.com/users/octocat/received_events type: type: string example: User site_admin: type: boolean starred_at: type: string example: '"2020-07-09T00:17:55Z"' parents: type: array items: type: object properties: sha: type: string example: 7638417db6d59f3c431d3e1f261cc637155684cd url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/commits/7638417db6d59f3c431d3e1f261cc637155684cd html_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/commit/7638417db6d59f3c431d3e1f261cc637155684cd stats: type: object properties: additions: type: integer deletions: type: integer total: type: integer files: type: array items: type: object title: Diff Entry properties: sha: type: string example: bbcd538c8e72b8c175046e27cc8f907076331401 filename: type: string example: file1.txt status: type: string enum: - added - removed - modified - renamed - copied - changed - unchanged example: added additions: type: integer example: 103 deletions: type: integer example: 21 changes: type: integer example: 124 blob_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/blob/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt raw_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt contents_url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e patch: type: string example: >- @@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test previous_filename: type: string example: file.txt merge_base_commit: type: object title: Commit properties: url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e sha: type: string example: 6dcb09b5b57875f334f61aebed695e2e4193db5e node_id: type: string example: MDY6Q29tbWl0NmRjYjA5YjViNTc4NzVmMzM0ZjYxYWViZWQ2OTVlMmU0MTkzZGI1ZQ== html_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e comments_url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments commit: type: object properties: url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e author: type: object title: Git User properties: name: type: string example: '"Chris Wanstrath"' email: type: string example: '"[email protected]"' date: type: string example: '"2007-10-29T02:42:39.000-07:00"' committer: type: object title: Git User properties: name: type: string example: '"Chris Wanstrath"' email: type: string example: '"[email protected]"' date: type: string example: '"2007-10-29T02:42:39.000-07:00"' message: type: string example: Fix all the bugs comment_count: type: integer example: 0 tree: type: object properties: sha: type: string example: 827efc6d56897b048c772eb4087f854f46256132 url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/tree/827efc6d56897b048c772eb4087f854f46256132 verification: type: object title: Verification properties: verified: type: boolean reason: type: string payload: type: string nullable: true signature: type: string nullable: true author: type: object title: Simple User properties: name: nullable: true type: string email: nullable: true type: string login: type: string example: octocat id: type: integer example: 1 node_id: type: string example: MDQ6VXNlcjE= avatar_url: type: string format: uri example: https://github.com/images/error/octocat_happy.gif gravatar_id: type: string example: 41d064eb2195891e12d0413f63227ea7 nullable: true url: type: string format: uri example: https://api.github.com/users/octocat html_url: type: string format: uri example: https://github.com/octocat followers_url: type: string format: uri example: https://api.github.com/users/octocat/followers following_url: type: string example: https://api.github.com/users/octocat/following{/other_user} gists_url: type: string example: https://api.github.com/users/octocat/gists{/gist_id} starred_url: type: string example: https://api.github.com/users/octocat/starred{/owner}{/repo} subscriptions_url: type: string format: uri example: https://api.github.com/users/octocat/subscriptions organizations_url: type: string format: uri example: https://api.github.com/users/octocat/orgs repos_url: type: string format: uri example: https://api.github.com/users/octocat/repos events_url: type: string example: https://api.github.com/users/octocat/events{/privacy} received_events_url: type: string format: uri example: https://api.github.com/users/octocat/received_events type: type: string example: User site_admin: type: boolean starred_at: type: string example: '"2020-07-09T00:17:55Z"' committer: type: object title: Simple User properties: name: nullable: true type: string email: nullable: true type: string login: type: string example: octocat id: type: integer example: 1 node_id: type: string example: MDQ6VXNlcjE= avatar_url: type: string format: uri example: https://github.com/images/error/octocat_happy.gif gravatar_id: type: string example: 41d064eb2195891e12d0413f63227ea7 nullable: true url: type: string format: uri example: https://api.github.com/users/octocat html_url: type: string format: uri example: https://github.com/octocat followers_url: type: string format: uri example: https://api.github.com/users/octocat/followers following_url: type: string example: https://api.github.com/users/octocat/following{/other_user} gists_url: type: string example: https://api.github.com/users/octocat/gists{/gist_id} starred_url: type: string example: https://api.github.com/users/octocat/starred{/owner}{/repo} subscriptions_url: type: string format: uri example: https://api.github.com/users/octocat/subscriptions organizations_url: type: string format: uri example: https://api.github.com/users/octocat/orgs repos_url: type: string format: uri example: https://api.github.com/users/octocat/repos events_url: type: string example: https://api.github.com/users/octocat/events{/privacy} received_events_url: type: string format: uri example: https://api.github.com/users/octocat/received_events type: type: string example: User site_admin: type: boolean starred_at: type: string example: '"2020-07-09T00:17:55Z"' parents: type: array items: type: object properties: sha: type: string example: 7638417db6d59f3c431d3e1f261cc637155684cd url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/commits/7638417db6d59f3c431d3e1f261cc637155684cd html_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/commit/7638417db6d59f3c431d3e1f261cc637155684cd stats: type: object properties: additions: type: integer deletions: type: integer total: type: integer files: type: array items: type: object title: Diff Entry properties: sha: type: string example: bbcd538c8e72b8c175046e27cc8f907076331401 filename: type: string example: file1.txt status: type: string enum: - added - removed - modified - renamed - copied - changed - unchanged example: added additions: type: integer example: 103 deletions: type: integer example: 21 changes: type: integer example: 124 blob_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/blob/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt raw_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt contents_url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e patch: type: string example: >- @@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test previous_filename: type: string example: file.txt status: type: string enum: - diverged - ahead - behind - identical example: ahead ahead_by: type: integer example: 4 behind_by: type: integer example: 5 total_commits: type: integer example: 6 commits: type: array items: type: object title: Commit properties: url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e sha: type: string example: 6dcb09b5b57875f334f61aebed695e2e4193db5e node_id: type: string example: MDY6Q29tbWl0NmRjYjA5YjViNTc4NzVmMzM0ZjYxYWViZWQ2OTVlMmU0MTkzZGI1ZQ== html_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e comments_url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments commit: type: object properties: url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e author: type: object title: Git User properties: name: type: string example: '"Chris Wanstrath"' email: type: string example: '"[email protected]"' date: type: string example: '"2007-10-29T02:42:39.000-07:00"' committer: type: object title: Git User properties: name: type: string example: '"Chris Wanstrath"' email: type: string example: '"[email protected]"' date: type: string example: '"2007-10-29T02:42:39.000-07:00"' message: type: string example: Fix all the bugs comment_count: type: integer example: 0 tree: type: object properties: sha: type: string example: 827efc6d56897b048c772eb4087f854f46256132 url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/tree/827efc6d56897b048c772eb4087f854f46256132 verification: type: object title: Verification properties: verified: type: boolean reason: type: string payload: type: string nullable: true signature: type: string nullable: true author: type: object title: Simple User properties: name: nullable: true type: string email: nullable: true type: string login: type: string example: octocat id: type: integer example: 1 node_id: type: string example: MDQ6VXNlcjE= avatar_url: type: string format: uri example: https://github.com/images/error/octocat_happy.gif gravatar_id: type: string example: 41d064eb2195891e12d0413f63227ea7 nullable: true url: type: string format: uri example: https://api.github.com/users/octocat html_url: type: string format: uri example: https://github.com/octocat followers_url: type: string format: uri example: https://api.github.com/users/octocat/followers following_url: type: string example: https://api.github.com/users/octocat/following{/other_user} gists_url: type: string example: https://api.github.com/users/octocat/gists{/gist_id} starred_url: type: string example: https://api.github.com/users/octocat/starred{/owner}{/repo} subscriptions_url: type: string format: uri example: https://api.github.com/users/octocat/subscriptions organizations_url: type: string format: uri example: https://api.github.com/users/octocat/orgs repos_url: type: string format: uri example: https://api.github.com/users/octocat/repos events_url: type: string example: https://api.github.com/users/octocat/events{/privacy} received_events_url: type: string format: uri example: https://api.github.com/users/octocat/received_events type: type: string example: User site_admin: type: boolean starred_at: type: string example: '"2020-07-09T00:17:55Z"' committer: type: object title: Simple User properties: name: nullable: true type: string email: nullable: true type: string login: type: string example: octocat id: type: integer example: 1 node_id: type: string example: MDQ6VXNlcjE= avatar_url: type: string format: uri example: https://github.com/images/error/octocat_happy.gif gravatar_id: type: string example: 41d064eb2195891e12d0413f63227ea7 nullable: true url: type: string format: uri example: https://api.github.com/users/octocat html_url: type: string format: uri example: https://github.com/octocat followers_url: type: string format: uri example: https://api.github.com/users/octocat/followers following_url: type: string example: https://api.github.com/users/octocat/following{/other_user} gists_url: type: string example: https://api.github.com/users/octocat/gists{/gist_id} starred_url: type: string example: https://api.github.com/users/octocat/starred{/owner}{/repo} subscriptions_url: type: string format: uri example: https://api.github.com/users/octocat/subscriptions organizations_url: type: string format: uri example: https://api.github.com/users/octocat/orgs repos_url: type: string format: uri example: https://api.github.com/users/octocat/repos events_url: type: string example: https://api.github.com/users/octocat/events{/privacy} received_events_url: type: string format: uri example: https://api.github.com/users/octocat/received_events type: type: string example: User site_admin: type: boolean starred_at: type: string example: '"2020-07-09T00:17:55Z"' parents: type: array items: type: object properties: sha: type: string example: 7638417db6d59f3c431d3e1f261cc637155684cd url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/commits/7638417db6d59f3c431d3e1f261cc637155684cd html_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/commit/7638417db6d59f3c431d3e1f261cc637155684cd stats: type: object properties: additions: type: integer deletions: type: integer total: type: integer files: type: array items: type: object title: Diff Entry properties: sha: type: string example: bbcd538c8e72b8c175046e27cc8f907076331401 filename: type: string example: file1.txt status: type: string enum: - added - removed - modified - renamed - copied - changed - unchanged example: added additions: type: integer example: 103 deletions: type: integer example: 21 changes: type: integer example: 124 blob_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/blob/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt raw_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt contents_url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e patch: type: string example: >- @@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test previous_filename: type: string example: file.txt files: type: array items: type: object title: Diff Entry properties: sha: type: string example: bbcd538c8e72b8c175046e27cc8f907076331401 filename: type: string example: file1.txt status: type: string enum: - added - removed - modified - renamed - copied - changed - unchanged example: added additions: type: integer example: 103 deletions: type: integer example: 21 changes: type: integer example: 124 blob_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/blob/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt raw_url: type: string format: uri example: >- https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt contents_url: type: string format: uri example: >- https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e patch: type: string example: '@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test' previous_filename: type: string example: file.txt