gitbutlerapp/gitbutler · error
--diff and --no-diff flags can only be used with commits, no
Error message
--diff and --no-diff flags can only be used with commits, not branches
What it means
Same branch/commit split in `but reword`: `--diff`/`--no-diff` control whether the editor shows the commit diff while rewording, which only applies to commits. Any explicit `ShowDiffInEditor` value other than Unspecified is rejected on the branch arm.
Source
Thrown at crates/but/src/command/legacy/reword.rs:55
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(
ctx,
commit.commit_id,
out,
message,
format,
show_diff_in_editor,View on GitHub (pinned to caf1f223d3)
Solutions
- Drop the flag when rewording a branch
- Or reword a commit: `but reword --diff <sha>`
- Adjust aliases so diff flags are added only for commit targets
Example fix
# before but reword --diff my-branch # error: --diff and --no-diff flags can only be used with commits, not branches # after but reword my-branch # no diff flags on branches but reword --diff 4a2f9c1 # diff display applies to commits
Defensive patterns
Strategy: validation
Validate before calling
# Only add diff flags for commit-looking targets case "$target" in *[0-9a-f][0-9a-f][0-9a-f]*) but reword --diff "$target" ;; # commit sha *) but reword "$target" ;; # branch esac
Prevention
- Leave --diff/--no-diff out of branch rename invocations
- Scope always-on diff aliases to commit rewords only
- When a reword fails on flag/target mismatch, re-check the target kind first
When it happens
Trigger: Running `but reword --diff <branch>` or `but reword --no-diff <branch>`; the branch arm checks the diff preference and bails.
Common situations: Aliases that always pass --no-diff; scripts shared between commit and branch rewords without branching on target kind.
Related errors
- --fix-formatting flag can only be used with commits, not bra
- 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/c18454ffe11e5775.
Report an issue: GitHub.