Skip to main content
This helper wraps the /api/v1/repos/diff-commit endpoint and is designed for workflows that already have git diff --binary output available.
const diff = await fs.readFile("dist/generated.patch", "utf8");

const result = await repo.createCommitFromDiff({
  targetBranch: "main",
  expectedHeadSha: currentHeadSha,
  commitMessage: "Apply generated SDK patch",
  author: { name: "Diff Bot", email: "diff@example.com" },
  committer: { name: "Diff Bot", email: "diff@example.com" },
  diff,
});

console.log(result.commitSha);
console.log(result.refUpdate.newSha);
console.log(result.refUpdate.oldSha);
createCommitFromDiff shares the same branch metadata (expectedHeadSha, baseBranch, ephemeral, ephemeralBase) as createCommit. Instead of calling .addFile(), pass the patch contents through the diff field. The SDK accepts strings, Uint8Array, ArrayBuffer, Blob/File objects, or any iterable/async iterable of byte chunks and handles chunking + base64 encoding. The gateway applies the patch with git apply --cached --binary, so make sure your diff is compatible with that command. It must include file headers (diff --git), mode lines, and hunk headers. Empty patches and patches that do not apply cleanly result in a RefUpdateError with the mapped status ( conflict, precondition_failed, etc.) and partial ref update information.

Options

ParameterTypeDescription
targetBranch (TypeScript)
target_branch (Python)
RequiredBranch name that will receive the commit.
commitMessage (TypeScript)
commit_message (Python)
RequiredThe commit message.
authorRequiredProvide name and email for the commit author.
diffRequiredThe patch content (string, bytes, or async iterable).
expectedHeadSha (TypeScript)
expected_head_sha (Python)
OptionalCommit SHA that must match the remote tip.
baseBranch (TypeScript)
base_branch (Python)
OptionalBranch to seed from if target doesn’t exist.
ephemeralOptionalStore in the ephemeral namespace.
ephemeralBase (TypeScript)
ephemeral_base (Python)
OptionalUse when the base branch is also ephemeral.
committerOptionalProvide name and email. Defaults to author if omitted.

Response

FieldTypeDescription
commitSha (TypeScript)
commit_sha (Python)
StringThe SHA of the created commit
treeSha (TypeScript)
tree_sha (Python)
StringThe SHA of the commit’s tree object
targetBranch (TypeScript)
target_branch (Python)
StringThe branch that received the commit
packBytes (TypeScript)
pack_bytes (Python)
NumberSize of the uploaded pack in bytes
refUpdate (TypeScript)
ref_update (Python)
ObjectContains branch, oldSha/old_sha, and newSha/new_sha