gitbutlerapp/gitbutler · error

Cannot amend a conflicted commit

Error message

Cannot amend a conflicted commit

What it means

but-workspace's commit_amend refuses to amend a commit whose tree contains unresolved merge conflicts. Amending such a commit would embed conflict markers into history, so the library fails fast with this message before performing any rebase work.

Solutions

  1. Resolve the conflicts in the target commit (edit files to remove conflict markers, then restage/reassign the files into that commit) before amending
  2. Choose a different, non-conflicted commit as the amend target
  3. Abort or redo the operation that left the commit conflicted (e.g. re-run the rebase and resolve first)
  4. Check `but status`/workspace output for conflicted markers on the commit before scripting an amend

Example fix

// before
editor.commit_amend(conflicted_commit, message, source)?; // panics/bails
// after
if editor.find_selectable_commit(conflicted_commit)?.1.id.attach(editor.repo()).is_conflicted() {
    resolve_conflicts_first()?;
}
editor.commit_amend(conflicted_commit, message, source)?;
Defensive patterns

Strategy: validation

Validate before calling

fn can_amend(editor: &WorkspaceEditor, commit: impl CommitLike) -> bool {
    !commit.attach(editor.repo()).is_conflicted()
}

Type guard

fn is_conflicted(commit: &gix::Commit) -> bool { commit.clone().attach(commit.repo).is_conflicted() }

Try / catch

match editor.commit_amend(target, msg, source) {
    Err(e) if e.to_string().contains("Cannot amend a conflicted commit") => resolve_conflicts_then_retry(),
    other => other,
}

Prevention

When it happens

Trigger: Calling WorkspaceEditor::commit_amend (or any public wrapper like `but amend`) targeting a commit whose attached gix::Commit reports is_conflicted() == true — typically a commit produced or rebased during an unresolved merge.

Common situations: Users attempt to amend the tip of a branch that was just created from a conflicted rebase or merge that was committed in a conflicted state; automation scripts iterate over assignments and hit a conflicted commit mid-stack.

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/ca947f94b134d69e. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-workspace/src/commit/commit_amend.rs:66

/// have been written to the shared object database at that point; it is
/// unreachable and gets garbage-collected eventually.
///
/// `context_lines` define how many diff context lines are being used for
/// this particular function call. The provided `context_lines` MUST align
/// with the `context_lines` value used to generate the `DiffSpec`s passed
/// in the `changes` parameter.
pub fn commit_amend<'ws, 'meta, M: RefMetadata>(
    mut editor: Editor<'ws, 'meta, M>,
    commit: impl ToCommitSelector,
    changes: Vec<DiffSpec>,
    context_lines: u32,
    source: ChangeSource<'_>,
) -> Result<CommitAmendOutcome<'ws, 'meta, M>> {
    let (target_selector, target) = editor.find_selectable_commit(commit)?;

    let target_id = target.id;
    if target.attach(editor.repo()).is_conflicted() {
        bail!("Cannot amend a conflicted commit")
    }
    // An immutable pick would be replaced in the step graph while the rebase copies
    // its descendants verbatim and never moves the (immutable) refs pointing at it -
    // the amended commit would be written but stay unreachable, with this function
    // still reporting success. Fail fast instead.
    let Step::Pick(target_pick) = editor.lookup_step(target_selector)? else {
        bail!("BUG: Expected pick step from commit selector. This should never happen");
    };
    if !target_pick.mutable {
        bail!(
            "cannot amend into {target_id}: the commit is immutable (not part of a mutable branch)"
        );
    }

    // Clone before `create_commit` consumes the vec — needed afterwards
    // to determine which changes were consumed (not rejected).
    let all_changes = changes.clone();
    let create_out = create_commit(

View on GitHub (pinned to 58e5313667)