zed-industries/zed · error
git merge-base failed: {stderr}
Error message
git merge-base failed: {stderr} What it means
Error raised when the supplementary `git merge-base <ref> HEAD` invocation (used to compute the merge base while building a tree diff against a merge-base reference) exits with a non-zero status. The message carries the raw git stderr, which typically explains why the merge base could not be computed (e.g. bad revision, not a valid commit, repository corruption).
Source
Thrown at crates/git/src/repository.rs:1969
"--",
]
.map(OsString::from)
.to_vec(),
DiffTreeType::Since { base, head } => [
"diff-tree",
"-r",
"-z",
"--abbrev=64",
"--no-renames",
base.as_str(),
head.as_str(),
"--",
]
.map(OsString::from)
.to_vec(),
};
self.executor
.spawn(async move {
let git = git?;
let output = git.build_command(&args).output().await?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
anyhow::bail!("git diff-tree failed: {stderr}");
}
let stdout = String::from_utf8_lossy(&output.stdout);
let mut tree_diff = stdout.parse::<TreeDiff>()?;
let Some(merge_base_ref) = merge_base_ref else {
return Ok(tree_diff);
};
let Some(working_directory) = working_directory else {
return Ok(tree_diff);
};
if !tree_diff
.entriesView on GitHub (pinned to 5a9b9558db)
Solutions
- Verify the ref still exists: `git rev-parse --verify <merge_base_ref>`, and fetch the remote to restore pruned tracking refs.
- Handle unrelated histories upstream: skip the recreated-file comparison when no merge base exists.
- Run `git merge-base <ref> HEAD` manually to see the exact stderr.
- If both refs are valid but merge-base still fails, run `git fsck` to check for corrupt objects.
Defensive patterns
Strategy: try-catch
Validate before calling
if git.run(&["rev-parse", "--verify", "--quiet", &format!("{merge_base_ref}^{{commit}}")]).await.is_err() {
// base ref is gone: skip the recreated-file comparison
} Try / catch
match diff_result {
Err(e) if e.to_string().contains("merge-base failed") => {
// ref pruned or unrelated histories: degrade to the plain tree diff
}
other => other?,
} Prevention
- Fetch (with --prune) before comparing against remote-tracking refs.
- Skip merge-base comparisons when histories are known to be unrelated.
- Validate refs immediately before use; cached ref names go stale after upstream deletions.
When it happens
Trigger: `merge_base_ref` does not resolve (deleted remote branch or pruned tracking ref); HEAD and the base have no common ancestor (unrelated histories produce `fatal: Not a valid commit name` or no merge base); corrupt objects referenced by either ref.
Common situations: Comparing against a branch whose remote-tracking ref was pruned by `git fetch --prune`; forks with grafted or unrelated histories; comparing a branch against an upstream it never shared history with.
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
- git merge-base --is-ancestor failed
- git status failed: {stderr}
- git diff-tree failed: {stderr}
- git worktree list failed: {stderr}
- git worktree add failed: {stderr}
AI-assisted analysis of zed-industries/zed@5a9b9558db (2026-08-20).
Data as JSON: /api/errors/69c10fa375414259.
Report an issue: GitHub.