gitbutlerapp/gitbutler · error

Target must be a commit ID or branch, not

Error message

Target must be a commit ID or branch, not {}

What it means

`but show` accepts a target that resolves to a commit ID or a branch `CliId` (branches are delegated to `show_branch`). Any other `CliId` kind (e.g. a file/hunk marker) cannot be 'shown' as a commit, so the command bails naming the kind via `kind_for_humans()`.

Solutions

  1. Use a commit ID or branch name: `but show <commit-id|branch>`.
  2. Check the ID's kind via `but status`/`but log` output; use the appropriate command for files/hunks instead of `show`.
  3. If you intend to view a branch, pass the branch ID/name so `show_branch` runs.

Example fix

// before: file marker ID
but show f:src/main.rs
// error: Target must be a commit ID or branch, not file
// after
but show 3f9c1ab   # or a branch name
but status         # for file-level info
Defensive patterns

Strategy: type-guard

Validate before calling

if !matches!(cli_id, CliId::CommitId(_) | CliId::Branch(_)) {
    eprintln!("but show expects a commit ID or branch; got {}", cli_id.kind_for_humans());
    std::process::exit(2);
}

Type guard

fn is_showable(id: &CliId) -> bool {
    matches!(id, CliId::CommitId(_) | CliId::Branch(_))
}

Try / catch

match result {
    Err(e) if e.to_string().starts_with("Target must be a commit ID or branch") => {
        eprintln!("use `but status` for files/hunks; `but show` is for commits/branches");
    }
    Err(e) => return Err(e),
    Ok(v) => v,
}

Prevention

When it happens

Trigger: Running `but show` with an ID that resolves to a non-commit, non-branch CLI ID — e.g. an uncommitted file or hunk ID produced by `but status`/marking — instead of a commit or branch ID.

Common situations: Passing a file marker ID from the TUI/status output to `show`; scripting that copies the wrong column of IDs; typos where a workspace entity ID is mistaken for a commit ID.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/bd1f562ceccc3e38. Report an issue: GitHub.

Appendix: source

Thrown at crates/but/src/command/legacy/show.rs:83

        commit.id
    } else if cli_ids.len() > 1 {
        bail!(
            "Commit ID '{}' is ambiguous. Found {} matches",
            commit_id_str,
            cli_ids.len()
        );
    } else {
        match &cli_ids[0] {
            CliId::Commit {
                commit: CommitId { commit_id, .. },
                id: _,
            } => *commit_id,
            CliId::Branch(branch) => {
                // This is a branch identified by CLI ID, show the branch
                return show_branch(ctx, out, &branch.name, verbose, &id_map);
            }
            _ => {
                bail!(
                    "Target must be a commit ID or branch, not {}",
                    cli_ids[0].kind_for_humans()
                );
            }
        }
    };

    // Get commit and file details
    let repo = ctx.repo.get()?;
    let raw_commit = repo.find_commit(commit_id)?;
    let decoded = raw_commit.decode()?;

    // Get diff with first parent
    let parent_id = raw_commit.parent_ids().next().map(|id| id.detach());
    let tree_changes = but_core::diff::TreeChanges::from_trees(&repo, parent_id, commit_id)?;

    // Extract change-id if present (try both header names)
    let change_id = decoded

View on GitHub (pinned to 58e5313667)