{"record":{"id":"ca947f94b134d69e","repo":"gitbutlerapp/gitbutler","slug":"cannot-amend-a-conflicted-commit","errorCode":null,"errorMessage":"Cannot amend a conflicted commit","messagePattern":"Cannot amend a conflicted commit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/commit/commit_amend.rs","lineNumber":66,"sourceCode":"/// have been written to the shared object database at that point; it is\n/// unreachable and gets garbage-collected eventually.\n///\n/// `context_lines` define how many diff context lines are being used for\n/// this particular function call. The provided `context_lines` MUST align\n/// with the `context_lines` value used to generate the `DiffSpec`s passed\n/// in the `changes` parameter.\npub fn commit_amend<'ws, 'meta, M: RefMetadata>(\n    mut editor: Editor<'ws, 'meta, M>,\n    commit: impl ToCommitSelector,\n    changes: Vec<DiffSpec>,\n    context_lines: u32,\n    source: ChangeSource<'_>,\n) -> Result<CommitAmendOutcome<'ws, 'meta, M>> {\n    let (target_selector, target) = editor.find_selectable_commit(commit)?;\n\n    let target_id = target.id;\n    if target.attach(editor.repo()).is_conflicted() {\n        bail!(\"Cannot amend a conflicted commit\")\n    }\n    // An immutable pick would be replaced in the step graph while the rebase copies\n    // its descendants verbatim and never moves the (immutable) refs pointing at it -\n    // the amended commit would be written but stay unreachable, with this function\n    // still reporting success. Fail fast instead.\n    let Step::Pick(target_pick) = editor.lookup_step(target_selector)? else {\n        bail!(\"BUG: Expected pick step from commit selector. This should never happen\");\n    };\n    if !target_pick.mutable {\n        bail!(\n            \"cannot amend into {target_id}: the commit is immutable (not part of a mutable branch)\"\n        );\n    }\n\n    // Clone before `create_commit` consumes the vec — needed afterwards\n    // to determine which changes were consumed (not rejected).\n    let all_changes = changes.clone();\n    let create_out = create_commit(","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/commit/commit_amend.rs#L48-L84","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Resolve the conflicts in the target commit (edit files to remove conflict markers, then restage/reassign the files into that commit) before amending","Choose a different, non-conflicted commit as the amend target","Abort or redo the operation that left the commit conflicted (e.g. re-run the rebase and resolve first)","Check `but status`/workspace output for conflicted markers on the commit before scripting an amend"],"exampleFix":"// before\neditor.commit_amend(conflicted_commit, message, source)?; // panics/bails\n// after\nif editor.find_selectable_commit(conflicted_commit)?.1.id.attach(editor.repo()).is_conflicted() {\n    resolve_conflicts_first()?;\n}\neditor.commit_amend(conflicted_commit, message, source)?;","handlingStrategy":"validation","validationCode":"fn can_amend(editor: &WorkspaceEditor, commit: impl CommitLike) -> bool {\n    !commit.attach(editor.repo()).is_conflicted()\n}","typeGuard":"fn is_conflicted(commit: &gix::Commit) -> bool { commit.clone().attach(commit.repo).is_conflicted() }","tryCatchPattern":"match editor.commit_amend(target, msg, source) {\n    Err(e) if e.to_string().contains(\"Cannot amend a conflicted commit\") => resolve_conflicts_then_retry(),\n    other => other,\n}","preventionTips":["Check is_conflicted() on the target before scripting amends","Keep workspace conflicts resolved before running batch operations","Surface conflict state in tooling UIs before offering amend actions"],"tags":["git","conflict","amend","precondition"],"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"}