Skip to main content
// Compare feature branch to main
const diff = await repo.getBranchDiff({
  branch: "feature/new-auth",
  base: "main", // optional, defaults to default branch
});

console.log(`Changed files: ${diff.stats.files}`);
console.log(`+${diff.stats.additions} -${diff.stats.deletions}`);

diff.files.forEach((file) => {
  if (file.state === "renamed") {
    console.log(`Renamed: ${file.oldPath} -> ${file.path} (${file.rawState})`);
  }
});

// Filter to specific files
const filteredDiff = await repo.getBranchDiff({
  branch: "feature/new-auth",
  paths: ["src/auth.ts", "src/utils/token.ts"],
});

Options

branch
string
required
The branch name to get the diff for
base
string
Base branch to compare against (defaults to repository’s default branch)
ephemeral
string
When true, resolves the branch under the ephemeral namespace
ephemeralBase
string
When true, resolves the base branch under the ephemeral namespace
paths
string
Array of file paths to filter the diff. When provided, only returns diffs for the specified files and bypasses size/type filtering

Response

stats
object
Summary with files, additions, deletions, and changes
files
array
List of changed files with path, oldPath, state, rawState, and diff content

Notes

  • For renamed files, path is the new location and oldPath is the previous location
  • state is normalized to renamed, while rawState preserves Git’s original rename code (for example R054, where 054 is the similarity score)