{"record":{"id":"ae75e812746d24e1","repo":"gitbutlerapp/gitbutler","slug":"fix-formatting-flag-can-only-be-used-with-commit","errorCode":null,"errorMessage":"--fix-formatting flag can only be used with commits, not branches","messagePattern":"--fix-formatting flag can only be used with commits, not branches","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/reword.rs","lineNumber":49,"sourceCode":"    if message.is_none() && !format && !out.format().allows_human_ui() {\n        return Err(bad_input(\n            \"A message must be provided via --message (-m) for this output format\",\n        )\n        .into());\n    }\n\n    let mut guard = ctx.exclusive_worktree_access();\n    let id_map = IdMap::new_from_context(ctx, guard.read_permission())?;\n\n    let target = {\n        let repo = ctx.repo.get()?;\n        target.resolve_in_workspace(&repo, &id_map, Purpose::Target, None)?\n    };\n\n    match target.into_branch_or_commit()? {\n        BranchOrCommit::Branch(BranchArg(name)) => {\n            if format {\n                return Err(anyhow::anyhow!(\n                    \"--fix-formatting flag can only be used with commits, not branches\"\n                )\n                .into());\n            }\n            if !matches!(show_diff_in_editor, ShowDiffInEditor::Unspecified) {\n                return Err(anyhow::anyhow!(\n                    \"--diff and --no-diff flags can only be used with commits, not branches\"\n                )\n                .into());\n            }\n            edit_branch_name(ctx, &name, out, message, guard.write_permission())?;\n        }\n        BranchOrCommit::Commit(commit) => {\n            // Rewording a landed commit is lost work: the rewritten commit is\n            // dropped again on the next `but pull`.\n            MergedUpstream::from_ctx(ctx, allow_merged)?\n                .ensure_commit_not_merged(commit.commit_id)?;\n            edit_commit_message_by_id_and_reword_commit(","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but/src/command/legacy/reword.rs#L31-L67","documentation":"`but reword` resolves the target into a branch or a commit; `--fix-formatting` only exists on the commit path (rewrite the message and reformat it), so the branch arm rejects it immediately. Rewording a branch supports renaming and an optional message only.","triggerScenarios":"Running `but reword --fix-formatting <branch>` — the target resolves to `BranchOrCommit::Branch` and the flag check bails.","commonSituations":"Habit from rewording commits carried over to branch targets; shell history edit changing the target but not the flags.","solutions":["Drop the flag when rewording a branch: `but reword <branch>`","Or target a commit instead: `but reword --fix-formatting <sha>`","Check `but reword --help` for which flags apply to each target kind"],"exampleFix":"# before\nbut reword --fix-formatting my-branch\n# error: --fix-formatting flag can only be used with commits, not branches\n\n# after\nbut reword my-branch                  # branch rename / message only\nbut reword --fix-formatting 4a2f9c1   # formatting applies to commits","handlingStrategy":"validation","validationCode":"# Only add --fix-formatting for commit-looking targets\ncase \"$target\" in\n  *[0-9a-f][0-9a-f][0-9a-f]*) but reword --fix-formatting \"$target\" ;;  # commit sha\n  *)                            but reword \"$target\" ;;                   # branch\nesac","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check `but reword --help` for which flags apply to branches vs commits","Keep separate aliases for branch renames and commit rewords","Decide flag sets from the target kind, not from a shared template"],"tags":["reword","flag-combination","usage","commit-vs-branch"],"backgroundTag":"invalid-flag-combination","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}