{"record":{"id":"e4fd181e042be1e3","repo":"gitbutlerapp/gitbutler","slug":"failed-to-unapply-branch-due-to-conflicts-while-re","errorCode":null,"errorMessage":"Failed to unapply branch due to conflicts while rebuilding the workspace merge commit: {}","messagePattern":"Failed to unapply branch due to conflicts while rebuilding the workspace merge commit: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/unapply.rs","lineNumber":543,"sourceCode":"    ) -> anyhow::Result<WorkspaceMergeAfterUnapply> {\n        let mut tips = future_workspace_tips.to_vec();\n        let report_workspace_merge = !tips.is_empty();\n        if tips.is_empty() {\n            tips.push(base_tip_after_unapply(ws, future_workspace_tips)?);\n        }\n        let outcome = WorkspaceCommit::from_new_merge_with_tips(tips, &ws.graph, repo, None)?;\n        ensure_workspace_merge_has_no_conflicts(&outcome)?;\n        let workspace_commit_id = outcome.workspace_commit_id;\n        Ok(WorkspaceMergeAfterUnapply {\n            workspace_commit_id,\n            workspace_merge: report_workspace_merge.then_some(outcome),\n        })\n    }\n\n    fn ensure_workspace_merge_has_no_conflicts(\n        outcome: &crate::commit::merge::Outcome,\n    ) -> anyhow::Result<()> {\n        ensure!(\n            !outcome.has_conflicts(),\n            \"Failed to unapply branch due to conflicts while rebuilding the workspace merge commit: {}\",\n            describe_conflicting_stacks(&outcome.conflicting_stacks)\n        );\n        Ok(())\n    }\n\n    fn describe_conflicting_stacks(\n        conflicting_stacks: &[crate::commit::merge::ConflictingStack],\n    ) -> String {\n        let ref_names = conflicting_stacks\n            .iter()\n            .filter_map(|stack| stack.ref_name.as_ref())\n            .map(|ref_name| ref_name.shorten().to_string())\n            .collect::<Vec<_>>();\n        if ref_names.is_empty() {\n            format!(\"{} stack(s)\", conflicting_stacks.len())\n        } else {","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/unapply.rs#L525-L561","documentation":"Thrown by `ensure_workspace_merge_has_no_conflicts` in crates/but-workspace/src/branch/unapply.rs:543 after `gitbutler` recomputes the workspace merge commit while un-applying a branch. When the synthetic merge produces conflicts across stacks, the unapply is aborted rather than leaving the workspace in a conflicted state. The message includes a description of the conflicting stacks.","triggerScenarios":"Calling the unapply-branch API (workspace_branch_and_ancestors flow) when the branch being removed from the workspace cannot be merged out cleanly, i.e. the rebuilt workspace merge commit would have conflicts between remaining stacks or the unapplied branch's changes.","commonSituations":"Overlapping edits between two applied branches; the unapplied branch contains changes that were also made on the integration branch; diverged stacks with conflicting hunks in the same files; stale workspace state after upstream changes.","solutions":["Read the conflicting stacks from the error message and manually resolve the conflicts before retrying the unapply","Merge/rebase the conflicting branch into its peer branch first, then unapply","Update the workspace/integration branch (fetch and rebase) so the rebuilt merge applies cleanly","As a last resort, commit or stash the affected changes, unapply, and re-apply the branch"],"exampleFix":"// before\nworkspace.unapply_branch(branch_ref); // aborts with conflicts\n// after\n// resolve conflicting hunks between the two branches first\nworkspace.merge_branch_into_peer(conflicting_branch)?;\nworkspace.unapply_branch(branch_ref)?;","handlingStrategy":"try-catch","validationCode":"// preview merge conflicts before unapplying\nlet outcome = workspace.simulate_unapply(branch_ref)?;\nif outcome.has_conflicts() {\n    eprintln!(\"resolve first: {:?}\", outcome.conflicting_stacks);\n    return;\n}","typeGuard":null,"tryCatchPattern":"match workspace.unapply_branch(branch_ref) {\n    Err(e) if e.to_string().contains(\"conflicts while rebuilding\") => resolve_conflicts_and_retry(),\n    other => other?,\n}","preventionTips":["Keep applied branches non-overlapping in the files they touch","Rebase branches onto the integration branch before unapplying","Sync workspace state after upstream fetches before mutating stacks"],"tags":["git","merge-conflict","workspace"],"backgroundTag":"merge-conflict","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"}