gitbutlerapp/gitbutler · error
Cannot cherry-pick above a reference
Error message
Cannot cherry-pick above a reference
What it means
Insertion 'above' a position is defined relative to a commit/selector, not a named reference. When `relative_to` is `RelativeTo::Reference(_)` and `side` is `InsertSide::Above`, the library cannot compute the target position and rejects the combination.
Solutions
- Use `InsertSide::Below` with the reference, so commits land on top of it
- Resolve the reference to its tip commit and pass `RelativeTo::Commit(selector)` when 'above' is intended
- Pass a commit selector instead of a reference for above-insertion
Example fix
// before cherry_pick_commits(repo, meta, commits, &RelativeTo::Reference(ref_name), InsertSide::Above)?; // after let tip = reference_tip_selector(repo, &ref_name)?; cherry_pick_commits(repo, meta, commits, &RelativeTo::Commit(tip), InsertSide::Above)?;
Defensive patterns
Strategy: validation
Validate before calling
if matches!(relative_to, RelativeTo::Reference(_)) && side == InsertSide::Above {
anyhow::bail!("use a commit selector or InsertSide::Below when targeting a reference");
} Prevention
- Constrain UI options so 'above' is only offered for commit targets
- Document the reference+below-only contract of cherry_pick_commits in caller code
When it happens
Trigger: Calling `cherry_pick_commits` with `relative_to = RelativeTo::Reference(ref_name)` and `side = InsertSide::Above`.
Common situations: UI code that lets users pick 'insert above' while targeting a branch reference instead of a specific commit; scripts copying parameters between API variants.
Related errors
- argument ' ' must be a non-negative integer that fits in…
- argument ' ' must be an integer that fits in isize
- Cannot derive a worktree directory from
- cannot mix operations that require `materialize` and…
- Cannot move branch onto itself
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/45a10bf32453f17f.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-workspace/src/commit/cherry_pick.rs:40
pub fn cherry_pick_commits<'ws, 'meta, M: RefMetadata>(
mut editor: Editor<'ws, 'meta, M>,
source_commits: impl IntoIterator<Item = gix::ObjectId>,
relative_to: RelativeTo,
side: InsertSide,
) -> anyhow::Result<(SuccessfulRebase<'ws, 'meta, M>, Vec<Selector>)> {
let mut seen = HashSet::new();
let sources = source_commits
.into_iter()
.filter(|id| seen.insert(*id))
.collect::<Vec<_>>();
if sources.is_empty() {
bail!("No commits were provided to cherry-pick")
}
if matches!(
(&relative_to, side),
(RelativeTo::Reference(_), InsertSide::Above)
) {
bail!("Cannot cherry-pick above a reference")
}
let target = relative_to.to_selector(&editor)?;
let mut inserted_selectors = Vec::with_capacity(sources.len());
let mut previous_selector = None;
for source in sources {
// Give the copy its own change ID, retaining all other metadata.
let mut template = editor.find_commit(source)?;
let mut headers = Headers::try_from_commit(&template.inner).unwrap_or_default();
headers.change_id = Headers::from_config(&editor.repo().config_snapshot()).change_id;
headers.set_in_commit(&mut template.inner);
let template_id = editor.new_commit(template, DateMode::CommitterUpdateAuthorKeep)?;
let (anchor, insert_side) = match previous_selector {
Some(selector) => (selector, InsertSide::Above),
None => (target, side),
};View on GitHub (pinned to 58e5313667)