---
title: "Get diff between two commits"
method: GET
path: "/api/diff"
tags: ["Git"]
---

# Get diff between two commits

`GET /api/diff`

Returns a structured diff between two git refs using a two-dot comparison. See [git-diff](https://git-scm.com/docs/git-diff) for details.

## Query parameters

- `repo` string, required — The fully-qualified repository name.
- `base` string, required — The base git ref (branch, tag, or commit SHA) to diff from.
- `head` string, required — The head git ref (branch, tag, or commit SHA) to diff to.
- `path` string — Restrict the diff to changes touching this file path. Omit to diff all changes between the two refs.

## Response `200`

Structured diff between the two refs.

- PublicGetDiffResponse
  - `files` object[], required — The list of changed files.
    - `oldPath` string, nullable, required — The file path before the change. `null` for added files.
    - `newPath` string, nullable, required — The file path after the change. `null` for deleted files.
    - `hunks` object[], required — The list of changed regions within the file.
      - `oldRange` object, required — The line range in the old file.
        - `start` integer, required — The 1-based line number where the range starts.
        - `lines` integer, required — The number of lines the range spans.
      - `newRange` object, required — The line range in the new file.
        - `start` integer, required — The 1-based line number where the range starts.
        - `lines` integer, required — The number of lines the range spans.
      - `heading` string — Optional context heading extracted from the @@ line, typically the enclosing function or class name.
      - `body` string, required — The diff content, with each line prefixed by a space (context), + (addition), or - (deletion).

## Other responses

- `400` — Invalid query parameters or git ref.
- `404` — Repository not found.
- `500` — Unexpected diff failure.

---

[API](https://skmtc.dev/sourcebot/apis/sourcebot-public-api.md) · [All operations](https://skmtc.dev/sourcebot/apis/sourcebot-public-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/sourcebot/sourcebot-public-api/revisions/b0ed96fb7103/schema)
