gitbutlerapp/gitbutler · error

Cannot uncommit hunks that would result in merge conflicts

Error message

Cannot uncommit hunks that would result in merge conflicts

What it means

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.

Solutions

  1. refresh the workspace/hunk view (re-run `but status`) to get current hunk ids and retry
  2. commit or discard local edits to the affected files first
  3. uncommit the whole commit instead of individual hunks, then re-stage what you want

Example fix

// before
but uncommit 3abc --hunk h2   # stale hunk id after edits
// after
but status                     # refresh ids
but uncommit 3abc --hunk <fresh-hunk-id>
Defensive patterns

Strategy: try-catch

Validate before calling

// refresh hunk ids right before selection
let hunks = fresh_hunk_ids_from_status(); // don't reuse cached ids across edits

Try / catch

match uncommit_hunks(ctx, ids) {
    Err(e) if e.to_string().contains("merge conflicts") => {
        eprintln!("Hunks conflict with the workspace; refresh ids or uncommit the whole commit.");
    }
    other => other?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/b0cf9ba5cf429059. Report an issue: GitHub.

Appendix: source

Thrown at crates/but/src/command/legacy/squash.rs:1616

                } => SquashOutcome::UncommitBranch {
                    branch_names: source_branches,
                },
            };
            Ok((outcome, Some(ws)))
        }
        ExecutableSquashOperation::UncommitHunks { source, changes } => {
            {
                let but_api::commit::types::MoveChangesResult { workspace } =
                    but_api::commit::uncommit::commit_uncommit_changes_only_with_perm(
                        ctx,
                        source.commit_id,
                        changes.clone(),
                        None,
                        DryRun::Yes,
                        perm,
                    )?;

                anyhow::ensure!(
                    !workspace.is_conflicted(),
                    "Cannot uncommit hunks that would result in merge conflicts"
                );
            }

            let but_api::commit::types::MoveChangesResult { workspace: _ } =
                but_api::commit::uncommit::commit_uncommit_changes_with_perm(
                    ctx,
                    source.commit_id,
                    changes,
                    None,
                    DryRun::No,
                    perm,
                )?;

            Ok((SquashOutcome::UncommitHunk { source }, None))
        }
    }

View on GitHub (pinned to 58e5313667)