{"record":{"id":"c6cdd6fad98d4893","repo":"gitbutlerapp/gitbutler","slug":"refusing-to-land-branch-commit-s-on-unnam","errorCode":null,"errorMessage":"Refusing to land `{branch}`: {} commit(s) on unnamed segment(s) below it would also be published to {target_display}. Pass --whole-stack to land `{branch}` together with everything below it.","messagePattern":"Refusing to land `(.+?)`: (.+?) commit\\(s\\) on unnamed segment\\(s\\) below it would also be published to (.+?)\\. Pass --whole-stack to land `(.+?)` together with everything below it\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/land/mod.rs","lineNumber":427,"sourceCode":"        // deleted still holds commits that \"land the entire stack\" would have to include.\n        if let Some(top) = scan.upper_segments.first() {\n            bail!(\n                \"Refusing to land `{branch}` with --whole-stack: it is not the top of its stack. \\\n                 --whole-stack lands the entire stack; name its top segment `{top}` instead.\",\n            );\n        }\n        bail!(\n            \"Refusing to land `{branch}` with --whole-stack: it is not the top of its stack — \\\n             unnamed segment(s) with commits sit above it (their branch refs no longer exist), so \\\n             landing `{branch}` would not land the entire stack.\",\n        );\n    }\n    // Key off the commits below, not the segment names: segments whose branch ref was deleted are\n    // unnamed but their commits would be published all the same.\n    let publishes_below = scan.commits_below > 0 || !scan.lower_segments.is_empty();\n    if publishes_below && !whole_stack {\n        if scan.lower_segments.is_empty() {\n            bail!(\n                \"Refusing to land `{branch}`: {} commit(s) on unnamed segment(s) below it would \\\n                 also be published to {target_display}. Pass --whole-stack to land `{branch}` \\\n                 together with everything below it.\",\n                scan.commits_below,\n            );\n        }\n        bail!(\n            \"Refusing to land `{branch}`: it is stacked on top of {} other segment(s) ({}) \\\n             whose commits would also be published to {target_display}. Land the bottom segment \\\n             `{}`, or pass --whole-stack to land `{branch}` together with everything below it.\",\n            scan.lower_segments.len(),\n            scan.lower_segments.join(\", \"),\n            scan.lower_segments.last().expect(\"non-empty checked above\"),\n        );\n    }\n\n    if !scan.conflicted.is_empty() {\n        bail!(","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/land/mod.rs#L409-L445","documentation":"`validate_branch_landing` refuses to land a branch when it sits on top of commits from unnamed segments below it (segments whose branch refs were deleted but whose commits remain). Landing the branch would also publish those orphaned commits to the target, which without `--whole-stack` is not an allowed partial publish, so the operation is refused with a count of the affected commits.","triggerScenarios":"Calling `branch_land` without `whole_stack` where `scan.commits_below > 0` and `scan.lower_segments` is empty — the branch is stacked above unnamed segments (deleted refs) whose commits would be implicitly published to `target_display`.","commonSituations":"Lower branches were deleted with `git branch -D` or via UI without landing, leaving their commits in the stack; rebasing onto a workspace with orphaned commits; inheriting a workspace from a teammate whose refs differ.","solutions":["Pass `--whole-stack` (`but land <branch> --whole-stack`) to explicitly publish everything below together with the branch.","Restore a named branch on the orphaned lower commits, land that bottom segment first, then land this branch.","Discard the orphaned lower commits if they are not wanted, then land normally."],"exampleFix":"// before\nbut land feature-2   // refused: 3 commit(s) on unnamed segment(s) below\n// after\nbut land feature-2 --whole-stack   # explicitly includes everything below","handlingStrategy":"validation","validationCode":"// detect orphaned commits below the branch before landing without --whole-stack\nconst ws = await api.workspaceState();\nconst below = ws.stacks.flatMap(s => s.segments)\n  .filter(seg => seg.position < positionOf(branch) && !seg.refName);\nconst orphanCommits = below.reduce((n, seg) => n + seg.commitCount, 0);\nif (orphanCommits > 0) throw new Error(`Use --whole-stack or handle ${orphanCommits} orphaned commit(s) below first`);","typeGuard":"null","tryCatchPattern":"try {\n  await api.land(branch);\n} catch (e) {\n  if (String(e).includes('Pass --whole-stack')) {\n    await api.land(branch, { wholeStack: true }); // or handle orphaned commits first\n  } else throw e;\n}","preventionTips":["Land bottom-up in a stack so orphaned lower commits never accumulate.","After deleting lower branch refs, decide explicitly: land (--whole-stack) or discard the commits.","Review unnamed segments during workspace cleanup sessions."],"tags":["git","stacked-branches","deleted-refs","validation"],"backgroundTag":"invalid-state-transition","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"}