> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sourcebot.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Get diff between two commits

> 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.



## OpenAPI

````yaml /api-reference/sourcebot-public.openapi.json get /api/diff
openapi: 3.0.3
info:
  title: Sourcebot Public API
  version: v5.0.4
  description: >-
    OpenAPI description for the public Sourcebot REST endpoints used for search,
    repository listing, and file browsing. Authentication is instance-dependent:
    API keys are the standard integration mechanism, OAuth bearer tokens are
    EE-only, and some instances may allow anonymous access.
servers: []
security:
  - bearerToken: []
  - apiKeyHeader: []
  - {}
tags:
  - name: Search & Navigation
    description: Code search and symbol navigation endpoints.
  - name: Repositories
    description: Repository listing and metadata endpoints.
  - name: Git
    description: Git history, diff, and file content endpoints.
  - name: System
    description: System health and version endpoints.
  - name: Enterprise (EE)
    description: Enterprise endpoints for user management and audit logging.
paths:
  /api/diff:
    get:
      tags:
        - Git
      summary: Get diff between two commits
      description: >-
        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.
      operationId: getDiff
      parameters:
        - schema:
            type: string
            description: The fully-qualified repository name.
          required: true
          description: The fully-qualified repository name.
          name: repo
          in: query
        - schema:
            type: string
            description: The base git ref (branch, tag, or commit SHA) to diff from.
          required: true
          description: The base git ref (branch, tag, or commit SHA) to diff from.
          name: base
          in: query
        - schema:
            type: string
            description: The head git ref (branch, tag, or commit SHA) to diff to.
          required: true
          description: The head git ref (branch, tag, or commit SHA) to diff to.
          name: head
          in: query
        - schema:
            type: string
            description: >-
              Restrict the diff to changes touching this file path. Omit to diff
              all changes between the two refs.
          required: false
          description: >-
            Restrict the diff to changes touching this file path. Omit to diff
            all changes between the two refs.
          name: path
          in: query
      responses:
        '200':
          description: Structured diff between the two refs.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicGetDiffResponse'
        '400':
          description: Invalid query parameters or git ref.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiServiceError'
        '404':
          description: Repository not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiServiceError'
        '500':
          description: Unexpected diff failure.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiServiceError'
components:
  schemas:
    PublicGetDiffResponse:
      type: object
      properties:
        files:
          type: array
          items:
            type: object
            properties:
              oldPath:
                type: string
                nullable: true
                description: The file path before the change. `null` for added files.
              newPath:
                type: string
                nullable: true
                description: The file path after the change. `null` for deleted files.
              hunks:
                type: array
                items:
                  type: object
                  properties:
                    oldRange:
                      type: object
                      properties:
                        start:
                          type: integer
                          description: The 1-based line number where the range starts.
                        lines:
                          type: integer
                          description: The number of lines the range spans.
                      required:
                        - start
                        - lines
                      description: The line range in the old file.
                    newRange:
                      type: object
                      properties:
                        start:
                          type: integer
                          description: The 1-based line number where the range starts.
                        lines:
                          type: integer
                          description: The number of lines the range spans.
                      required:
                        - start
                        - lines
                      description: The line range in the new file.
                    heading:
                      type: string
                      description: >-
                        Optional context heading extracted from the @@ line,
                        typically the enclosing function or class name.
                    body:
                      type: string
                      description: >-
                        The diff content, with each line prefixed by a space
                        (context), + (addition), or - (deletion).
                  required:
                    - oldRange
                    - newRange
                    - body
                description: The list of changed regions within the file.
            required:
              - oldPath
              - newPath
              - hunks
          description: The list of changed files.
      required:
        - files
    PublicApiServiceError:
      type: object
      properties:
        statusCode:
          type: number
        errorCode:
          type: string
        message:
          type: string
      required:
        - statusCode
        - errorCode
        - message
      description: Structured error response returned by Sourcebot public API endpoints.
  securitySchemes:
    bearerToken:
      type: http
      scheme: bearer
      description: >-
        Bearer authentication header of the form `Bearer <token>`, where
        `<token>` is your API key.
    apiKeyHeader:
      type: apiKey
      in: header
      name: X-Sourcebot-Api-Key
      description: >-
        Header of the form `X-Sourcebot-Api-Key: <token>`, where `<token>` is
        your API key.

````