API Reference
Diff
Compare two refs and see file-level changes.
Compare Refs
GET /v1/repos/:slug/diff?base=main&head=feature-x
GET /v1/repos/:namespace/:slug/diff?base=main&head=feature-xQuery Parameters
| Param | Required | Description |
|---|---|---|
base | Yes | Branch name, tag, or commit SHA |
head | Yes | Branch name, tag, or commit SHA |
patch | No | Include unified diff patches (default: false) |
context | No | Context lines for patches (default: 3, max: 20) |
Response 200:
{
"base": "7f3b...",
"head": "a1c2...",
"files": [
{
"path": "src/index.ts",
"status": "modified",
"old_sha": "d4e5...",
"new_sha": "f6a7..."
},
{
"path": "README.md",
"status": "added",
"old_sha": null,
"new_sha": "b2c3..."
}
],
"total_files_changed": 2,
"total_additions": 17,
"total_deletions": 3
}File Statuses
| Status | Meaning |
|---|---|
added | New file in head |
modified | Changed between base and head |
removed | Deleted in head |
Each file entry includes old_sha and new_sha (the blob SHAs before and after). null when the file didn't exist on that side.
Unified Diff Patches
Add ?patch=true to include git-compatible unified diff for each file:
GET /v1/repos/:slug/diff?base=main&head=feature-x&patch=true&context=5Each file in the response will include a patch field:
{
"path": "src/auth.ts",
"status": "modified",
"old_sha": "d4e5...",
"new_sha": "f6a7...",
"patch": "--- a/src/auth.ts\n+++ b/src/auth.ts\n@@ -10,3 +10,4 @@\n function login() {\n+ validate();\n return token;\n }"
}SDK Example
// Without patches
const { data } = await git.diff.compare("my-repo", "main", "feature-x");
// With unified diff patches
const { data } = await git.diff.compare("my-repo", "main", "feature-x", {
patch: true,
context: 5,
});
for (const file of data.files) {
console.log(file.path, file.status);
if (file.patch) console.log(file.patch);
}