yamadashy/repomix · error · RepomixError

Failed to get git diffs: ${error.message}

Error message

Failed to get git diffs: ${error.message}

What it means

getGitDiffs runs `git diff` commands for the work tree and the staged area, then wraps any underlying failure (non-zero exit, git missing, not a repo) into a single RepomixError with this message. The original git error text is appended so the concrete cause (e.g. 'not a git repository', 'fatal: bad object') is visible in the message.

Source

Thrown at src/core/git/gitDiffHandle.ts:88

  let gitDiffResult: GitDiffResult | undefined;

  if (config.output.git?.includeDiffs) {
    try {
      // Use the first directory as the git repository root
      // Usually this would be the root of the project
      const gitRoot = rootDirs[0] || config.cwd;
      const [workTreeDiffContent, stagedDiffContent] = await Promise.all([
        deps.getWorkTreeDiff(gitRoot),
        deps.getStagedDiff(gitRoot),
      ]);

      gitDiffResult = {
        workTreeDiffContent,
        stagedDiffContent,
      };
    } catch (error) {
      if (error instanceof Error) {
        throw new RepomixError(`Failed to get git diffs: ${error.message}`);
      }
    }
  }

  return gitDiffResult;
};

View on GitHub (pinned to f465ad9093)

Solutions

  1. Run repomix inside a git repository (or `git init` / `git clone` the project) — `git diff` requires a repo.
  2. Install git and confirm `git --version` works in the same shell/environment.
  3. Read the appended cause in the message and fix that underlying git error (e.g. remove stale .git/index.lock, repair the repo).

Example fix

// before (plain zip download)
npx repomix --include-diffs ./project-zip
// after
npm install -g repomix
cd project-zip && git init && git add -A && git commit -m init
npx repomix --include-diffs
Defensive patterns

Strategy: try-catch

Validate before calling

import { execFileSync } from 'node:child_process';
const isGitRepo = (dir: string) => {
  try { execFileSync('git', ['-C', dir, 'rev-parse', '--is-inside-work-tree'], { stdio: 'ignore' }); return true; }
  catch { return false; }
};
if (!isGitRepo(targetDir)) throw new Error('Target is not a git repository; diffs unavailable.');

Type guard

const isRepomixDiffError = (e: unknown): e is RepomixError & { message: string } =>
  e instanceof RepomixError && e.message.startsWith('Failed to get git diffs:');

Try / catch

try {
  const diffs = await getGitDiffs(...);
} catch (error) {
  if (error instanceof RepomixError && error.message.startsWith('Failed to get git diffs:')) {
    console.warn('Git diffs skipped:', error.message);
  } else throw error;
}

Prevention

When it happens

Trigger: Calling getGitDiffs (or the --include-diffs code path) when the target directory is not a git repository, git is not installed or not on PATH, or the git diff subprocess exits non-zero for any reason.

Common situations: Running repomix on a plain directory that was downloaded as a zip (no .git); a stripped-down Docker/CI image without git; corrupted index or lock file making `git diff` fail.

Related errors


AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29). Data as JSON: /api/errors/c1438f2de9a42893. Report an issue: GitHub.