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

  1. Drop the flag when rewording a branch
  2. Or reword a commit: `but reword --diff <sha>`
  3. 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

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


AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20). Data as JSON: /api/errors/c18454ffe11e5775. Report an issue: GitHub.