> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/go-gitea/gitea/llms.txt
> Use this file to discover all available pages before exploring further.

# Commit Endpoints

> Access and manage commit information via the Gitea API

The Gitea API provides endpoints for retrieving commit information, including individual commits, commit lists, and commit diffs.

## Get Single Commit

Retrieve a single commit by its SHA or git reference.

```bash theme={null}
GET /repos/{owner}/{repo}/git/commits/{sha}
```

### Path Parameters

<ParamField path="owner" type="string" required>
  Owner of the repository
</ParamField>

<ParamField path="repo" type="string" required>
  Name of the repository
</ParamField>

<ParamField path="sha" type="string" required>
  A git reference or commit SHA
</ParamField>

### Query Parameters

<ParamField query="stat" type="boolean" default="true">
  Include diff stats for the commit (disable for speedup)
</ParamField>

<ParamField query="verification" type="boolean" default="true">
  Include verification information for the commit (disable for speedup)
</ParamField>

<ParamField query="files" type="boolean" default="true">
  Include list of affected files (disable for speedup)
</ParamField>

### Response

<ResponseField name="sha" type="string">
  Commit SHA hash
</ResponseField>

<ResponseField name="url" type="string">
  API URL for the commit
</ResponseField>

<ResponseField name="html_url" type="string">
  Web URL to view the commit
</ResponseField>

<ResponseField name="commit" type="object">
  Commit information

  <ResponseField name="author" type="object">
    Author information

    <ResponseField name="name" type="string">
      Author name
    </ResponseField>

    <ResponseField name="email" type="string">
      Author email
    </ResponseField>

    <ResponseField name="date" type="string">
      Author date (ISO 8601)
    </ResponseField>
  </ResponseField>

  <ResponseField name="committer" type="object">
    Committer information (same structure as author)
  </ResponseField>

  <ResponseField name="message" type="string">
    Commit message
  </ResponseField>

  <ResponseField name="tree" type="object">
    Tree information

    <ResponseField name="sha" type="string">
      Tree SHA
    </ResponseField>

    <ResponseField name="url" type="string">
      API URL for the tree
    </ResponseField>
  </ResponseField>

  <ResponseField name="verification" type="object">
    Commit signature verification

    <ResponseField name="verified" type="boolean">
      Whether the signature is verified
    </ResponseField>

    <ResponseField name="reason" type="string">
      Verification status reason
    </ResponseField>
  </ResponseField>
</ResponseField>

<ResponseField name="parents" type="array">
  Array of parent commit metadata
</ResponseField>

<ResponseField name="files" type="array">
  Array of affected files

  <ResponseField name="filename" type="string">
    Path of the affected file
  </ResponseField>

  <ResponseField name="status" type="string">
    File status: `added`, `modified`, `deleted`
  </ResponseField>
</ResponseField>

<ResponseField name="stats" type="object">
  Commit statistics

  <ResponseField name="total" type="integer">
    Total lines changed
  </ResponseField>

  <ResponseField name="additions" type="integer">
    Lines added
  </ResponseField>

  <ResponseField name="deletions" type="integer">
    Lines deleted
  </ResponseField>
</ResponseField>

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://gitea.example.com/api/v1/repos/username/repo-name/git/commits/abc123" \
    -H "Authorization: token YOUR_TOKEN"
  ```

  ```json Response theme={null}
  {
    "sha": "abc123def456",
    "url": "https://gitea.example.com/api/v1/repos/username/repo-name/git/commits/abc123def456",
    "html_url": "https://gitea.example.com/username/repo-name/commit/abc123def456",
    "commit": {
      "author": {
        "name": "John Doe",
        "email": "john@example.com",
        "date": "2024-03-10T12:00:00Z"
      },
      "committer": {
        "name": "John Doe",
        "email": "john@example.com",
        "date": "2024-03-10T12:00:00Z"
      },
      "message": "Add new feature",
      "tree": {
        "sha": "def789abc123",
        "url": "https://gitea.example.com/api/v1/repos/username/repo-name/git/trees/def789abc123"
      },
      "verification": {
        "verified": true,
        "reason": "valid"
      }
    },
    "parents": [
      {
        "sha": "parent123",
        "url": "https://gitea.example.com/api/v1/repos/username/repo-name/git/commits/parent123"
      }
    ],
    "files": [
      {
        "filename": "src/main.go",
        "status": "modified"
      }
    ],
    "stats": {
      "total": 15,
      "additions": 10,
      "deletions": 5
    }
  }
  ```
</CodeGroup>

## List All Commits

Get a list of all commits from a repository.

```bash theme={null}
GET /repos/{owner}/{repo}/commits
```

### Path Parameters

<ParamField path="owner" type="string" required>
  Owner of the repository
</ParamField>

<ParamField path="repo" type="string" required>
  Name of the repository
</ParamField>

### Query Parameters

<ParamField query="sha" type="string">
  SHA or branch to start listing commits from (usually 'master' or 'main')
</ParamField>

<ParamField query="path" type="string">
  Filepath of a file/directory to filter commits
</ParamField>

<ParamField query="since" type="string">
  Only commits after this date (ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ)
</ParamField>

<ParamField query="until" type="string">
  Only commits before this date (ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ)
</ParamField>

<ParamField query="stat" type="boolean" default="true">
  Include diff stats for every commit
</ParamField>

<ParamField query="verification" type="boolean" default="true">
  Include verification for every commit
</ParamField>

<ParamField query="files" type="boolean" default="true">
  Include list of affected files for every commit
</ParamField>

<ParamField query="not" type="string">
  Commits that match the given specifier will not be listed
</ParamField>

<ParamField query="page" type="integer" default="1">
  Page number of results (1-based)
</ParamField>

<ParamField query="limit" type="integer">
  Page size of results (ignored if used with 'path')
</ParamField>

### Response

Returns an array of commit objects (same structure as Get Single Commit).

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://gitea.example.com/api/v1/repos/username/repo-name/commits?sha=main&page=1&limit=10" \
    -H "Authorization: token YOUR_TOKEN"
  ```

  ```bash Filter by Date theme={null}
  curl -X GET "https://gitea.example.com/api/v1/repos/username/repo-name/commits?since=2024-03-01T00:00:00Z&until=2024-03-10T23:59:59Z" \
    -H "Authorization: token YOUR_TOKEN"
  ```

  ```bash Filter by Path theme={null}
  curl -X GET "https://gitea.example.com/api/v1/repos/username/repo-name/commits?path=src/main.go" \
    -H "Authorization: token YOUR_TOKEN"
  ```

  ```json Response theme={null}
  [
    {
      "sha": "abc123def456",
      "commit": {
        "author": {
          "name": "John Doe",
          "email": "john@example.com",
          "date": "2024-03-10T12:00:00Z"
        },
        "message": "Add new feature"
      },
      "html_url": "https://gitea.example.com/username/repo-name/commit/abc123def456"
    },
    {
      "sha": "def456abc789",
      "commit": {
        "author": {
          "name": "Jane Smith",
          "email": "jane@example.com",
          "date": "2024-03-09T15:30:00Z"
        },
        "message": "Fix bug in authentication"
      },
      "html_url": "https://gitea.example.com/username/repo-name/commit/def456abc789"
    }
  ]
  ```
</CodeGroup>

<Note>
  The response includes pagination headers:

  * `X-Total-Count`: Total number of commits
  * `X-Page`: Current page number
  * `X-PerPage`: Number of items per page
  * `X-PageCount`: Total number of pages
  * `X-HasMore`: Whether more pages exist
</Note>

## Download Commit Diff or Patch

Get a commit's diff or patch file.

```bash theme={null}
GET /repos/{owner}/{repo}/git/commits/{sha}.{diffType}
```

### Path Parameters

<ParamField path="owner" type="string" required>
  Owner of the repository
</ParamField>

<ParamField path="repo" type="string" required>
  Name of the repository
</ParamField>

<ParamField path="sha" type="string" required>
  SHA of the commit to get
</ParamField>

<ParamField path="diffType" type="string" required>
  Output format: `diff` or `patch`
</ParamField>

### Response

Returns plain text diff or patch content.

<CodeGroup>
  ```bash Get Diff theme={null}
  curl -X GET "https://gitea.example.com/api/v1/repos/username/repo-name/git/commits/abc123.diff" \
    -H "Authorization: token YOUR_TOKEN"
  ```

  ```bash Get Patch theme={null}
  curl -X GET "https://gitea.example.com/api/v1/repos/username/repo-name/git/commits/abc123.patch" \
    -H "Authorization: token YOUR_TOKEN"
  ```

  ```diff Response theme={null}
  diff --git a/src/main.go b/src/main.go
  index 1234567..abcdefg 100644
  --- a/src/main.go
  +++ b/src/main.go
  @@ -10,6 +10,7 @@ import (
   	"fmt"
   	"log"
   	"net/http"
  +	"os"
   )
   
   func main() {
  ```
</CodeGroup>

## Get Commit Pull Request

Retrieve the pull request that merged this commit.

```bash theme={null}
GET /repos/{owner}/{repo}/commits/{sha}/pull
```

### Path Parameters

<ParamField path="owner" type="string" required>
  Owner of the repository
</ParamField>

<ParamField path="repo" type="string" required>
  Name of the repository
</ParamField>

<ParamField path="sha" type="string" required>
  SHA of the commit
</ParamField>

### Response

Returns a pull request object if the commit was part of a merged pull request.

<ResponseField name="id" type="integer">
  Pull request ID
</ResponseField>

<ResponseField name="number" type="integer">
  Pull request number
</ResponseField>

<ResponseField name="title" type="string">
  Pull request title
</ResponseField>

<ResponseField name="state" type="string">
  Pull request state: `open`, `closed`, `merged`
</ResponseField>

<ResponseField name="merged" type="boolean">
  Whether the pull request was merged
</ResponseField>

<ResponseField name="merged_at" type="string">
  Timestamp when merged (ISO 8601)
</ResponseField>

<ResponseField name="merge_commit_sha" type="string">
  SHA of the merge commit
</ResponseField>

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://gitea.example.com/api/v1/repos/username/repo-name/commits/abc123/pull" \
    -H "Authorization: token YOUR_TOKEN"
  ```

  ```json Response theme={null}
  {
    "id": 42,
    "number": 10,
    "title": "Add new feature",
    "state": "closed",
    "merged": true,
    "merged_at": "2024-03-10T12:00:00Z",
    "merge_commit_sha": "abc123def456",
    "head": {
      "ref": "feature-branch",
      "sha": "def456abc789"
    },
    "base": {
      "ref": "main",
      "sha": "789abc123def"
    }
  }
  ```
</CodeGroup>

## Common Use Cases

### List Recent Commits

Get the most recent commits from the default branch:

```bash theme={null}
curl -X GET "https://gitea.example.com/api/v1/repos/username/repo-name/commits?limit=20" \
  -H "Authorization: token YOUR_TOKEN"
```

### Get Commits by Author

While the API doesn't have a direct author filter, you can filter commits after fetching them or use the `since` parameter combined with knowing when the author was active.

### Track File History

Get all commits that affected a specific file:

```bash theme={null}
curl -X GET "https://gitea.example.com/api/v1/repos/username/repo-name/commits?path=src/main.go" \
  -H "Authorization: token YOUR_TOKEN"
```

### Verify Commit Signatures

Include verification information for all commits:

```bash theme={null}
curl -X GET "https://gitea.example.com/api/v1/repos/username/repo-name/commits?verification=true" \
  -H "Authorization: token YOUR_TOKEN"
```
