{"record":{"id":"fbccdec4383bb62f","repo":"gitbutlerapp/gitbutler","slug":"cherry-picks-can-only-be-done-for-single-parent-co","errorCode":null,"errorMessage":"Cherry picks can only be done for single-parent commits. Merge-commits need to be re-merged","messagePattern":"Cherry picks can only be done for single-parent commits\\. Merge-commits need to be re-merged","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-rebase/src/cherry_pick.rs","lineNumber":81,"sourceCode":"        && commit_to_rebase.parents.contains(&base.id.detach())\n    {\n        return Ok(commit_to_rebase.id);\n    };\n\n    let mut cherry_pick = cherry_pick_tree(&base, &commit_to_rebase)?;\n    let tree_id = cherry_pick.tree.write()?;\n\n    let conflict_kind = gix::merge::tree::TreatAsUnresolved::forced_resolution();\n    if cherry_pick.has_unresolved_conflicts(conflict_kind) {\n        commit_from_conflicted_tree(base, commit_to_rebase, tree_id, cherry_pick, conflict_kind)\n    } else {\n        commit_from_unconflicted_tree(base, commit_to_rebase, tree_id, empty_commit)\n    }\n}\n\nfn set_parent(to_rebase: &mut gix::objs::Commit, new_parent: gix::ObjectId) -> anyhow::Result<()> {\n    if to_rebase.parents.len() > 1 {\n        bail!(\n            \"Cherry picks can only be done for single-parent commits. Merge-commits need to be re-merged\"\n        )\n    }\n    to_rebase.parents.clear();\n    to_rebase.parents.push(new_parent);\n    Ok(())\n}\n\n/// Rebase `to_rebase` onto `new_base`, dealing with the intricacies of conflicted trees, and return the newly\n/// merged tree.\n/// Note that all merges are made to succeed, possibly recording the original trees in a special tree.\nfn cherry_pick_tree<'repo>(\n    new_base: &but_core::Commit<'repo>,\n    to_rebase: &but_core::Commit<'repo>,\n) -> anyhow::Result<gix::merge::tree::Outcome<'repo>> {\n    let repo = to_rebase.id.repo;\n    let (base, ours, theirs) = find_cherry_pick_trees(new_base, to_rebase)?;\n    use but_core::RepositoryExt;","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-rebase/src/cherry_pick.rs#L63-L99","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Exclude merge commits from the commit range being rebased (e.g. use linear history or --no-merges equivalent filtering)","Re-create the merge manually after rebasing the two parents","Flatten the branch first (rebase -i, drop/squash merges) before using this API"],"exampleFix":"// before: including a merge commit in the rebase input\nfor commit in commits /* may include merges */ { rebase_cherry_pick(commit)?; }\n// after: filter merges out\nfor commit in commits.into_iter().filter(|c| c.parents.len() == 1) {\n    rebase_cherry_pick(commit)?;\n}","handlingStrategy":"validation","validationCode":"anyhow::ensure!(commit.parents.len() <= 1, \"commit {} is a merge commit and cannot be cherry-picked\", commit.id);","typeGuard":"fn is_cherry_pickable(c: &gix::objs::Commit) -> bool { c.parents.len() <= 1 }","tryCatchPattern":"match set_parent(&mut commit, new_parent) {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"Merge-commits\") => {\n        eprintln!(\"skip or re-merge merge commit {}\", commit.id);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Filter merge commits out of rebase inputs","Maintain linear history on branches fed to cherry-pick flows","Handle merges with a dedicated re-merge code path"],"tags":["git","rebase","merge-commit"],"backgroundTag":"unsupported-operation","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}