---
title: "Edit a site's pages and code: commit a diff to its source"
method: POST
path: "/sites/{id}/source/commits/diff"
tags: ["Sites"]
---

# Edit a site's pages and code: commit a diff to its source

`POST /sites/{id}/source/commits/diff`

## Request

- Base URL: `https://api.crevio.co/v1`
- URL: `https://api.crevio.co/v1/sites/{id}/source/commits/diff`
- Auth: API key in header `Authorization`

Applies a unified diff to the site's `main` branch as one commit, the way `git apply` would. It does not deploy: to put the commit live, call `POST /sites/{id}/deploy` with `commit_sha` set to the returned `sha`.

Send the output of `git diff`, or any unified diff whose paths are relative to the repository root with the usual `a/` and `b/` prefixes. New, deleted, renamed and binary files are supported, and hunk line counts are recounted, so a hand-written hunk only needs its context lines right. A diff that does not apply to `main` is refused with `422` and `param: diff`, with git's reason, and changes nothing. The same paths are refused as in `POST /sites/{id}/source/commits`: `..`, `.git/`, and environment files (`.env`, `.env.*`, `.dev.vars`), including as the source or target of a rename. At most 4 MiB.

Pass `expected_head_sha`, the `head_sha` your diff is based on. If `main` has moved the call fails with `409 stale_head` and `error.head_sha`, the current head: read the files again, rebuild the diff and retry. Without it, the call still fails the same way if `main` moves while the commit is pushed.

A diff that leaves every file as it was makes no commit and answers `changed: false` with the current head.

A repository that refuses the commit for another reason, such as a protected branch on a connected GitHub repository, answers `422 commit_rejected` with its reason.

## Path parameters

- `id` string, required

## Headers

- `Idempotency-Key` string

## Request body

- object
  - `message` string, required: The commit message, 1 to 5000 characters.
  - `diff` string, required: A unified diff against `main`, at most 4 MiB.
  - `expected_head_sha` string: The `head_sha` your diff is based on (from a source read or your last commit). If `main` is anywhere else the call fails with `409 stale_head` and changes nothing. A prefix of 7 or more characters is accepted.

## Response `200`

The commit `main` now points at

- object
  - `object` 'site_source_commit', required
  - `sha` string, required: The commit `main` now points at.
  - `previous_sha` string, required: The commit `main` pointed at before.
  - `changed` boolean, required: False when the operations left every file as it was: no commit was made and `sha` equals `previous_sha`.

## Other responses

- `401`: Authentication required
- `403`: Forbidden
- `404`: Resource not found
- `409`: `main` moved since `expected_head_sha`, or while the commit was being pushed. Nothing was committed. `error.head_sha` is where `main` is now: read the files you are changing again and retry against it.
- `422`: Validation error
- `429`: Rate limit exceeded — 600 requests per minute per owner on the free tier: every API key and OAuth token one person holds on an account shares one budget, and the account's team keys share another. Retry after the number of seconds in `Retry-After`.
- `503`: Feature not configured for this workspace

## Changes

- **2026-11-15** `56c22ab9b282`: 6 warning
  - added the new `idempotency_error` enum value to the `error/type` response property for the response status `401`
  - added the new `idempotency_error` enum value to the `error/type` response property for the response status `403`
  - added the new `idempotency_error` enum value to the `error/type` response property for the response status `404`
  - added the new `idempotency_error` enum value to the `error/type` response property for the response status `422`
  - …2 more
- **2026-11-15** `3d2d9bae7da4`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/crevio/apis/crevio-api-v1/changes/sites/:id/source/commits/diff/post.md)

---

[API](https://skmtc.dev/crevio/apis/crevio-api-v1.md) - [All operations](https://skmtc.dev/crevio/apis/crevio-api-v1/llms.txt) - [OpenAPI document](https://skmtc.dev/crevio/apis/crevio-api-v1/revisions/ccbd8fcbd6d7?raw)
