{"record":{"id":"b0cf9ba5cf429059","repo":"gitbutlerapp/gitbutler","slug":"cannot-uncommit-hunks-that-would-result-in-merge-c","errorCode":null,"errorMessage":"Cannot uncommit hunks that would result in merge conflicts","messagePattern":"Cannot uncommit hunks that would result in merge conflicts","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/squash.rs","lineNumber":1616,"sourceCode":"                } => SquashOutcome::UncommitBranch {\n                    branch_names: source_branches,\n                },\n            };\n            Ok((outcome, Some(ws)))\n        }\n        ExecutableSquashOperation::UncommitHunks { source, changes } => {\n            {\n                let but_api::commit::types::MoveChangesResult { workspace } =\n                    but_api::commit::uncommit::commit_uncommit_changes_only_with_perm(\n                        ctx,\n                        source.commit_id,\n                        changes.clone(),\n                        None,\n                        DryRun::Yes,\n                        perm,\n                    )?;\n\n                anyhow::ensure!(\n                    !workspace.is_conflicted(),\n                    \"Cannot uncommit hunks that would result in merge conflicts\"\n                );\n            }\n\n            let but_api::commit::types::MoveChangesResult { workspace: _ } =\n                but_api::commit::uncommit::commit_uncommit_changes_with_perm(\n                    ctx,\n                    source.commit_id,\n                    changes,\n                    None,\n                    DryRun::No,\n                    perm,\n                )?;\n\n            Ok((SquashOutcome::UncommitHunk { source }, None))\n        }\n    }","sourceCodeStart":1598,"sourceCodeEnd":1634,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/squash.rs#L1598-L1634","documentation":"Same dry-run conflict guard as the commit-level variant, but for partial uncommit of specific hunks (`but uncommit` with hunk selection). The dry-run move of the selected hunks into the workspace would conflict, so the operation is rejected before mutating anything.","triggerScenarios":"Running a hunk-level `but uncommit` where the chosen hunks' surrounding content in the workspace differs from the committed content: concurrent edits to the same lines, stale hunk ids after a rebase, or hunks overlapping each other's context.","commonSituations":"Selecting hunks from an interactive diff after manually editing nearby lines, uncommitting hunks whose line numbers shifted due to prior operations, or splitting a commit when later commits touch identical regions.","solutions":["refresh the workspace/hunk view (re-run `but status`) to get current hunk ids and retry","commit or discard local edits to the affected files first","uncommit the whole commit instead of individual hunks, then re-stage what you want"],"exampleFix":"// before\nbut uncommit 3abc --hunk h2   # stale hunk id after edits\n// after\nbut status                     # refresh ids\nbut uncommit 3abc --hunk <fresh-hunk-id>","handlingStrategy":"try-catch","validationCode":"// refresh hunk ids right before selection\nlet hunks = fresh_hunk_ids_from_status(); // don't reuse cached ids across edits","typeGuard":null,"tryCatchPattern":"match uncommit_hunks(ctx, ids) {\n    Err(e) if e.to_string().contains(\"merge conflicts\") => {\n        eprintln!(\"Hunks conflict with the workspace; refresh ids or uncommit the whole commit.\");\n    }\n    other => other?,\n}","preventionTips":["re-fetch hunk ids after any file edit or rebase","avoid uncommitting hunks from lines you edited locally","prefer whole-commit uncommit when hunks overlap"],"tags":["git","conflict","hunks"],"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"}