gitbutlerapp/gitbutler · error
--fix-formatting flag can only be used with commits, not bra
Error message
--fix-formatting flag can only be used with commits, not branches
What it means
`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.
Source
Thrown at crates/but/src/command/legacy/reword.rs:49
if message.is_none() && !format && !out.format().allows_human_ui() {
return Err(bad_input(
"A message must be provided via --message (-m) for this output format",
)
.into());
}
let mut guard = ctx.exclusive_worktree_access();
let id_map = IdMap::new_from_context(ctx, guard.read_permission())?;
let target = {
let repo = ctx.repo.get()?;
target.resolve_in_workspace(&repo, &id_map, Purpose::Target, None)?
};
match target.into_branch_or_commit()? {
BranchOrCommit::Branch(BranchArg(name)) => {
if format {
return Err(anyhow::anyhow!(
"--fix-formatting flag can only be used with commits, not branches"
)
.into());
}
if !matches!(show_diff_in_editor, ShowDiffInEditor::Unspecified) {
return Err(anyhow::anyhow!(
"--diff and --no-diff flags can only be used with commits, not branches"
)
.into());
}
edit_branch_name(ctx, &name, out, message, guard.write_permission())?;
}
BranchOrCommit::Commit(commit) => {
// Rewording a landed commit is lost work: the rewritten commit is
// dropped again on the next `but pull`.
MergedUpstream::from_ctx(ctx, allow_merged)?
.ensure_commit_not_merged(commit.commit_id)?;
edit_commit_message_by_id_and_reword_commit(View on GitHub (pinned to caf1f223d3)
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
Example fix
# before but reword --fix-formatting my-branch # error: --fix-formatting flag can only be used with commits, not branches # after but reword my-branch # branch rename / message only but reword --fix-formatting 4a2f9c1 # formatting applies to commits
Defensive patterns
Strategy: validation
Validate before calling
# Only add --fix-formatting for commit-looking targets case "$target" in *[0-9a-f][0-9a-f][0-9a-f]*) but reword --fix-formatting "$target" ;; # commit sha *) but reword "$target" ;; # branch esac
Prevention
- 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
When it happens
Trigger: Running `but reword --fix-formatting <branch>` — the target resolves to `BranchOrCommit::Branch` and the flag check bails.
Common situations: Habit from rewording commits carried over to branch targets; shell history edit changing the target but not the flags.
Related errors
- --diff and --no-diff flags can only be used with commits, no
- Conflicted uncommitted files can only be marked as resolved:
- --ai cannot be combined with a resolve subcommand. For one c
- Cannot use both --detect and --path options together
- Editor exited with non-zero status
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/ae75e812746d24e1.
Report an issue: GitHub.