Coregit
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-x

Query Parameters

ParamRequiredDescription
baseYesBranch name, tag, or commit SHA
headYesBranch name, tag, or commit SHA
patchNoInclude unified diff patches (default: false)
contextNoContext 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

StatusMeaning
addedNew file in head
modifiedChanged between base and head
removedDeleted 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=5

Each 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);
}

On this page