gitbutlerapp/gitbutler · error

Cherry picks can only be done for single-parent commits…

Error message

Cherry picks can only be done for single-parent commits. Merge-commits need to be re-merged

What it means

Cherry-pick style rebasing rewrites a commit to have exactly one new parent. Merge commits have two or more parents and cannot be expressed this way, so the library bails instead of silently flattening history. Merge commits must be handled by a re-merge strategy instead.

Solutions

  1. Exclude merge commits from the commit range being rebased (e.g. use linear history or --no-merges equivalent filtering)
  2. Re-create the merge manually after rebasing the two parents
  3. Flatten the branch first (rebase -i, drop/squash merges) before using this API

Example fix

// before: including a merge commit in the rebase input
for commit in commits /* may include merges */ { rebase_cherry_pick(commit)?; }
// after: filter merges out
for commit in commits.into_iter().filter(|c| c.parents.len() == 1) {
    rebase_cherry_pick(commit)?;
}
Defensive patterns

Strategy: validation

Validate before calling

anyhow::ensure!(commit.parents.len() <= 1, "commit {} is a merge commit and cannot be cherry-picked", commit.id);

Type guard

fn is_cherry_pickable(c: &gix::objs::Commit) -> bool { c.parents.len() <= 1 }

Try / catch

match set_parent(&mut commit, new_parent) {
    Ok(()) => {},
    Err(e) if e.to_string().contains("Merge-commits") => {
        eprintln!("skip or re-merge merge commit {}", commit.id);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling `set_parent` via `commit_from_unconflicted_tree` or `commit_from_conflicted_tree` while rebasing/cherry-picking a commit whose `parents` list has more than one entry.

Common situations: Rebasing a branch that contains a merge commit; applying a merge commit onto a workspace with cherry-pick semantics; automated scripts piping `git log` ranges that include merges into the rebase API.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/fbccdec4383bb62f. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-rebase/src/cherry_pick.rs:81

        && commit_to_rebase.parents.contains(&base.id.detach())
    {
        return Ok(commit_to_rebase.id);
    };

    let mut cherry_pick = cherry_pick_tree(&base, &commit_to_rebase)?;
    let tree_id = cherry_pick.tree.write()?;

    let conflict_kind = gix::merge::tree::TreatAsUnresolved::forced_resolution();
    if cherry_pick.has_unresolved_conflicts(conflict_kind) {
        commit_from_conflicted_tree(base, commit_to_rebase, tree_id, cherry_pick, conflict_kind)
    } else {
        commit_from_unconflicted_tree(base, commit_to_rebase, tree_id, empty_commit)
    }
}

fn set_parent(to_rebase: &mut gix::objs::Commit, new_parent: gix::ObjectId) -> anyhow::Result<()> {
    if to_rebase.parents.len() > 1 {
        bail!(
            "Cherry picks can only be done for single-parent commits. Merge-commits need to be re-merged"
        )
    }
    to_rebase.parents.clear();
    to_rebase.parents.push(new_parent);
    Ok(())
}

/// Rebase `to_rebase` onto `new_base`, dealing with the intricacies of conflicted trees, and return the newly
/// merged tree.
/// Note that all merges are made to succeed, possibly recording the original trees in a special tree.
fn cherry_pick_tree<'repo>(
    new_base: &but_core::Commit<'repo>,
    to_rebase: &but_core::Commit<'repo>,
) -> anyhow::Result<gix::merge::tree::Outcome<'repo>> {
    let repo = to_rebase.id.repo;
    let (base, ours, theirs) = find_cherry_pick_trees(new_base, to_rebase)?;
    use but_core::RepositoryExt;

View on GitHub (pinned to 58e5313667)