gitbutlerapp/gitbutler · error
Encountered conflict when merging tree
Error message
Encountered conflict when merging tree {tree_to_merge}{details} What it means
Thrown by the octopus (multi-parent) merge path in but-rebase when a tree-level merge leaves unresolved conflicts. The library merges a tree into the current one via gix's merge machinery and, if `merge.has_unresolved_conflicts` is true, aborts with this message plus the conflict details and a ConflictErrorContext carrying the conflicted paths.
Solutions
- Inspect the conflicted paths from the attached ConflictErrorContext and resolve those files manually, then retry the operation
- Check out one of the branches and resolve/rebase it first so the trees no longer conflict before the octopus merge
- Use merge options (e.g. favor-ours/theirs strategies available via merge_options) to auto-resolve in favor of one side
- Split the merge into sequential two-way merges so each conflict can be resolved incrementally
Example fix
// before
let merged = rebase.octopus_merge(&[tree_a, tree_b])?; // panics on conflict
// after
match rebase.octopus_merge(&[tree_a, tree_b]) {
Ok(m) => m,
Err(e) if e.downcast_ref::<ConflictErrorContext>().is_some() => {
let ctx = e.downcast_ref::<ConflictErrorContext>().unwrap();
resolve_paths_manually(&ctx.paths);
rebase.octopus_merge(&[tree_a, tree_b])?
}
Err(e) => return Err(e),
} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check for overlapping changes between trees
let conflicts = gix::merge::tree::conflicts(&base, &ours, &tree_to_merge)?;
if !conflicts.is_empty() { resolve_or_warn(&conflicts); } Type guard
fn has_conflict_ctx(e: &anyhow::Error) -> bool {
e.downcast_ref::<ConflictErrorContext>().is_some()
} Try / catch
match merge_result {
Err(e) if has_conflict_ctx(&e) => {
let ctx = e.downcast_ref::<ConflictErrorContext>().unwrap();
eprintln!("resolve these paths: {:?}", ctx.paths);
}
Err(e) => return Err(e),
Ok(m) => m,
} Prevention
- Rebase divergent branches before combining them in an octopus merge
- Use merge options with a favor-ours/favor-theirs strategy for auto-resolvable overlaps
- Surface conflicted paths to users instead of silently merging
- Keep stacks small so conflicts stay localized
When it happens
Trigger: Calling the octopus merge routine when the tree being merged (`tree_to_merge`) modifies the same paths as the current tree in incompatible ways, so the recursive/resolve merge produces conflicts instead of a clean tree.
Common situations: Rebasing or stacking commits where two branches touched the same lines or same file (add/add conflicts, rename conflicts); applying a workspace merge over divergent edits; automating branch combination where a human would normally resolve manually.
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
- Cannot merge : merging into / resulted in conflicts. Rebase…
- Base commit must exist if provided
- Cannot squash commits that would result in merge conflicts
- Cannot uncommit changes from a conflicted commit
- Cherry picks can only be done for single-parent commits…
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/0667d9a47d5c7769.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-rebase/src/merge.rs:72
Ok(but_core::Commit::from_id(commit_id.attach(repo))?
.tree_id_or_kind(TreeKind::Theirs)?
.detach())
})
.collect::<Result<Vec<_>, _>>()?
.into_iter();
let mut ours = trees_to_merge.next().expect("two or more trees");
let (merge_options, unresolved) = repo.merge_options_fail_fast()?;
let mut successfully_merged = vec![ours];
for tree_to_merge in trees_to_merge {
let mut merge = repo.merge_trees(
merge_base,
ours,
tree_to_merge,
repo.default_merge_labels(),
merge_options.clone(),
)?;
if merge.has_unresolved_conflicts(unresolved) {
return Err(anyhow!(
"Encountered conflict when merging tree {tree_to_merge}{details}",
details = merge_conflict_details(&successfully_merged)
)
.context(ConflictErrorContext {
paths: merge
.conflicts
.iter()
.map(|c| c.ours.location().to_owned())
.collect(),
}));
}
successfully_merged.push(tree_to_merge);
ours = merge.tree.write()?.detach();
}
target_merge_commit.tree = ours;
if but_core::commit::Headers::try_from_commit(&target_merge_commit).is_none() {
let headers = but_core::commit::Headers::from_config(&repo.config_snapshot());
headers.set_in_commit(&mut target_merge_commit);View on GitHub (pinned to 58e5313667)