> ## Documentation Index
> Fetch the complete documentation index at: https://code.storage/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# getCommitDiff()

> Get the diff for a specific commit.

<CodeGroup>
  ```typescript TypeScript theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
  // 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
    gitApplyCompatible: true, // generate raw diffs for use with git apply
  });

  // 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'],
  });
  ```

  ```python Python theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
  # Get commit diff (shows changes from parent)
  commit_diff = await repo.get_commit_diff(
      sha="abc123def456",
  )

  # Get commit diff compared to a specific base
  custom_diff = await repo.get_commit_diff(
      sha="abc123def456",
      base_sha="def789abc123",  # optional base commit to compare against
      git_apply_compatible=True,  # generate raw diffs for use with git apply
  )

  print(commit_diff["stats"])
  for file in commit_diff["files"]:
      print(f"{file['state']}: {file['path']}")
      if file["state"] == "renamed":
          print(f"Renamed: {file['oldPath']} -> {file['path']}")

  # Filter to specific files
  filtered_diff = await repo.get_commit_diff(
      sha="abc123def456",
      paths=["package.json", "src/main.py"],
  )
  ```

  ```go Go theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
  // Get commit diff (parent comparison)
  commitDiff, err := repo.GetCommitDiff(context.Background(), storage.GetCommitDiffOptions{
  	SHA: "abc123def456",
  })
  fmt.Println(commitDiff.Stats)

  // Compare against a specific base
  customDiff, err := repo.GetCommitDiff(context.Background(), storage.GetCommitDiffOptions{
  	SHA:           "abc123def456",
  	BaseSHA:       "def789abc123",
  	GitApplyCompatible: true, // generate raw diffs for use with git apply
  })

  // Filter to specific files
  filtered, err := repo.GetCommitDiff(context.Background(), storage.GetCommitDiffOptions{
  	SHA:   "abc123def456",
  	Paths: []string{"package.json", "src/main.go"},
  })
  ```
</CodeGroup>

## Options

<ParamField path="sha" type="string" required>
  The commit SHA to get the diff for
</ParamField>

<ParamField path="baseSha" type="string">
  Base commit SHA to compare against. If not specified, compares against the commit's parent(s)
</ParamField>

<ParamField path="gitApplyCompatible" type="boolean">
  When enabled, concatenate `files[].raw` in response order and apply the result against the
  selected base with `git apply`. Changes listed in `filteredFiles` are not included in the patch.
  Defaults to `false`, preserving review-oriented whitespace suppression.
</ParamField>

<ParamField path="paths" type="string">
  Array of file paths to filter the diff. When provided, only returns diffs for the specified files
  and bypasses size/type filtering
</ParamField>

## Response

<ResponseField name="stats" type="object">
  Summary with `files`, `additions`, `deletions`, and `changes`
</ResponseField>

<ResponseField name="files" type="array">
  List of changed files with `path`, `oldPath`, `state`, `rawState`, and diff content
</ResponseField>

<ResponseField name="filteredFiles" type="array">
  List of filtered files returned as metadata only (for example `path`, `oldPath`, `state`,
  `rawState`, `bytes`, and `isEof`) without diff content
</ResponseField>

## 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%
* When `gitApplyCompatible` is enabled, concatenate `files[].raw` in response order and apply the
  result against the selected base with `git apply`. Changes listed in `filteredFiles` are not
  included in the patch

## 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
