gitbutlerapp/gitbutler · error
Cannot uncommit commits that would result in merge conflicts
Error message
Cannot uncommit commits that would result in merge conflicts
What it means
Before actually uncommitting (undoing) a commit, the code performs the operation in `DryRun::Yes` mode and checks the resulting workspace for conflicts. This error aborts the uncommit when the dry run shows the workspace would end up conflicted, protecting the user from a half-applied undo.
Solutions
- commit or stash your working-tree changes, then retry `but uncommit`
- uncommit the most recent commit of the stack instead of an older one, so fewer overlapping moves occur
- resolve existing conflicts in the workspace first (check `but status` for conflicted state) before uncommitting
Example fix
// before but uncommit 3abc # workspace has edits to the same files // after git stash && but uncommit 3abc && git stash pop
Defensive patterns
Strategy: try-catch
Validate before calling
// check workspace health before uncommitting
if but_status_reports_conflicted() { eprintln!("Resolve conflicts first"); } Try / catch
match uncommit(ctx, id) {
Err(e) if e.to_string().contains("merge conflicts") => {
eprintln!("Commit/stash working-tree changes, then retry uncommit.");
}
other => other?,
} Prevention
- keep the working tree clean before stack surgery
- uncommit the tip of a stack rather than deep commits
- run `but status` and clear conflicts before undo operations
When it happens
Trigger: Running `but uncommit <commit>` where moving the commit's changes back into the workspace overlaps with divergent local changes: the commit's files are heavily modified in the workspace, other stacks touch the same paths, or the workspace state has diverged from the commit graph.
Common situations: Undoing a commit after manually editing the same files in the working tree, uncommitting an old commit from a stack that later commits also modified, or resolving one conflict by hand before another operation already left markers.
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
- Branch ' ' cannot be created: the target commit ( ) already…
- Cannot unapply workspace reference by checking out…
- merge conflict when computing workspace tree
- Ad-hoc (single-branch) branch moves are not supported…
- Branch ' ' already exists
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/07cf01d7666b8412.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/command/legacy/squash.rs:1552
MoveCommittedFilesOperation { target, .. },
) => SquashOutcome::Hunks { target, new_commit },
};
Ok((outcome, Some(ws)))
}
ExecutableSquashOperation::Uncommit(op) => {
if op.has_commit_sources() {
let but_api::commit::types::UncommitResult {
workspace,
uncommitted_ids: _,
} = but_api::commit::uncommit::commit_uncommit_only_with_perm(
ctx,
op.commit_sources().collect(),
None,
DryRun::Yes,
perm,
)?;
anyhow::ensure!(
!workspace.is_conflicted(),
"Cannot uncommit commits that would result in merge conflicts"
);
}
let snapshot_details = SnapshotDetails::new(OperationKind::UndoCommit);
let ws = but_transaction::with_transaction_with_perm(
ctx,
meta,
perm,
snapshot_details,
DryRun::No,
|mut tx| {
match &op {
UncommitOperation::Commits { sources } => {
if !sources.is_empty() {
tx.uncommit_commits(sources.iter().map(|c| c.commit_id))?;
}View on GitHub (pinned to 58e5313667)