{"record":{"id":"b57ec69c2a24c6c9","repo":"gitbutlerapp/gitbutler","slug":"commit-id-is-ambiguous-found-matches","errorCode":null,"errorMessage":"Commit ID '{}' is ambiguous. Found {} matches","messagePattern":"Commit ID '(.+?)' is ambiguous\\. Found (.+?) matches","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/show.rs","lineNumber":67,"sourceCode":"        }\n    }\n\n    // Not a branch, resolve the commit ID through the IdMap\n    let cli_ids = id_map.parse_using_context(commit_id_str, ctx)?;\n\n    let commit_id = if cli_ids.is_empty() {\n        // If not found in IdMap, try to parse as a git commit ID directly\n        let repo = ctx.repo.get()?;\n        let obj = repo\n            .rev_parse_single(commit_id_str)\n            .map_err(|_| anyhow::anyhow!(\"Commit '{commit_id_str}' not found\"))?;\n        let commit = obj\n            .object()?\n            .try_into_commit()\n            .map_err(|_| anyhow::anyhow!(\"'{commit_id_str}' is not a commit\"))?;\n        commit.id\n    } else if cli_ids.len() > 1 {\n        bail!(\n            \"Commit ID '{}' is ambiguous. Found {} matches\",\n            commit_id_str,\n            cli_ids.len()\n        );\n    } else {\n        match &cli_ids[0] {\n            CliId::Commit {\n                commit: CommitId { commit_id, .. },\n                id: _,\n            } => *commit_id,\n            CliId::Branch(branch) => {\n                // This is a branch identified by CLI ID, show the branch\n                return show_branch(ctx, out, &branch.name, verbose, &id_map);\n            }\n            _ => {\n                bail!(\n                    \"Target must be a commit ID or branch, not {}\",\n                    cli_ids[0].kind_for_humans()","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but/src/command/legacy/show.rs#L49-L85","documentation":"`but show` (crates/but/src/command/legacy/show.rs:67) resolves its argument through the IdMap of short CLI IDs; when the argument prefix matches more than one entity (cli_ids.len() > 1) it refuses to guess and reports the match count. Short IDs (often 2-character prefixes) are only usable when unique within the current workspace snapshot.","triggerScenarios":"Passing a short ID prefix that collides across entities, e.g. `but show ab` where two commits or branches share that prefix; the workspace changed between displaying the ID and running the command, introducing a new collision.","commonSituations":"Copy-pasting a truncated ID from stale TUI/status output; small workspaces where 1-2 hex characters collide frequently; scripts that cut SHAs to fixed short lengths.","solutions":["Lengthen the prefix until unique, or pass the full 40-character object ID.","Re-run `but status` to see the current short-ID assignments and pick an unambiguous one.","Remember the fallback path: any string not in the IdMap is parsed with rev_parse_single, so full SHAs and ref names always bypass ambiguity."],"exampleFix":"# before\nbut show ab\n# Commit ID 'ab' is ambiguous. Found 2 matches\n\n# after\nbut show ab9f31c04d8e2f7a1b3c5d6e7f8a9b0c1d2e3f4a","handlingStrategy":"validation","validationCode":"let matches = id_map.lookup(prefix);\nmatch matches.len() {\n    0 => /* fall back to rev_parse_single */,\n    1 => /* safe */,\n    _ => return Err(anyhow::anyhow!(\"prefix '{}' matches {} entities; extend it\", prefix, matches.len())),\n}","typeGuard":null,"tryCatchPattern":"if let Err(err) = show_command(&ctx, &out, id) {\n    if err.to_string().contains(\"ambiguous\") {\n        // retry with the full 40-char SHA captured from the original entity\n    }\n}","preventionTips":["Store full object IDs in scripts; shorten only at display time.","Refresh short IDs with `but status` right before using them.","Treat ambiguity as expected in small workspaces and auto-extend prefixes."],"tags":["cli","id-resolution","ambiguity","short-id"],"backgroundTag":"ambiguous-short-id","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}