Skip to main content
// Get commit diff (shows changes from parent)
const commitDiff = await repo.getCommitDiff({
  sha: "abc123def456...",
});

// Get commit diff compared to a specific base
const customDiff = await repo.getCommitDiff({
  sha: "abc123def456...",
  baseSha: "def789abc123...", // optional base commit to compare against
});

// Process file changes
commitDiff.files.forEach((file) => {
  console.log(`${file.state}: ${file.path}`);
  console.log(`Raw status: ${file.rawState}`);

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

// Filter to specific files
const filteredDiff = await repo.getCommitDiff({
  sha: "abc123def456...",
  paths: ["package.json", "src/main.ts"],
});

Options

sha
string
required
The commit SHA to get the diff for
baseSha
string
Base commit SHA to compare against. If not specified, compares against the commit’s parent(s)
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
filteredFiles
array
List of filtered files returned as metadata only (for example path, oldPath, state, rawState, bytes, and isEof) without 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)
  • Rename detection follows Git’s default similarity threshold of 50%

Additional Notes

  • Large files (>500KB) or files with too many changes (>2000 lines) are included in filtered_files without diff content
  • Binary files and lock files are automatically filtered
  • When path is specified, size and type filtering is bypassed—requested files are always returned with full diff content