{"record":{"id":"2c202a07d39c7ca0","repo":"gitbutlerapp/gitbutler","slug":"found-multiple-matches-for-commit-id","errorCode":null,"errorMessage":"Found multiple matches for {commit_id}","messagePattern":"Found multiple matches for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/id/mod.rs","lineNumber":1803,"sourceCode":"    /// Returns all known stacks.\n    pub fn stacks(&self) -> &Vec<StackWithId> {\n        self.indexed_stacks.borrow_owner()\n    }\n\n    /// Get a distinct commit by ID.\n    ///\n    /// Errors if the commit cannot be found or if there are multiple matches.\n    pub fn get_commit_by_id(&self, commit_id: gix::ObjectId) -> anyhow::Result<CommitWithId<'_>> {\n        let mut matches = self\n            .commits()\n            .filter(|commit_with_id| match commit_with_id {\n                CommitWithId::Local(commit) => commit.commit_id() == commit_id,\n                CommitWithId::Remote(commit) => commit.commit_id() == commit_id,\n            });\n\n        match (matches.next(), matches.next()) {\n            (Some(commit), None) => Ok(commit),\n            (Some(_), Some(_)) => Err(anyhow::anyhow!(\"Found multiple matches for {commit_id}\")),\n            _ => Err(anyhow::anyhow!(\"Could not find commit {commit_id}\")),\n        }\n    }\n\n    fn commits(&self) -> impl Iterator<Item = CommitWithId<'_>> {\n        let stack_commits = self.indexed_stacks.borrow_owner().iter().flat_map(|stack| {\n            stack.segments.iter().flat_map(|segment| {\n                segment\n                    .workspace_commits\n                    .iter()\n                    .map(CommitWithId::Local)\n                    .chain(segment.remote_commits.iter().map(CommitWithId::Remote))\n            })\n        });\n\n        stack_commits.chain(\n            // Commits owned by a linked worktree resolve exactly like workspace commits - they\n            // just live outside the stacks.","sourceCodeStart":1785,"sourceCodeEnd":1821,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/id/mod.rs#L1785-L1821","documentation":"When resolving a commit identifier against indexed stacks, the lookup expects at most one commit to match. If the iterator yields two or more commits with the same id across stacks/segments, the result is ambiguous and this error is thrown rather than guessing.","triggerScenarios":"Looking up a commit id that appears in more than one stack or in multiple segments of the indexed workspace — e.g., the same commit was pushed/applied to two stacks, or duplicated by a workspace rebuild — so `matches.next()` returns `Some` twice.","commonSituations":"A cherry-pick or duplicate apply placed the same commit in two branches; stale workspace index containing overlapping stack entries; referring to a short id that collides across stacks.","solutions":["Run `but status` to see which stacks contain the commit; disambiguate by operating on the specific stack/branch instead of the bare id.","Remove or de-duplicate the duplicated commit (unapply from one stack, or cherry-pick cleanup) and retry.","Rebuild/refresh the workspace index so stale duplicate entries are cleared."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before resolving, inspect stacks for the id\nlet count = workspace.iter().filter(|c| c.commit_id() == commit_id).count();\nif count > 1 { eprintln!(\"commit {} is duplicated across stacks; disambiguate first\", commit_id); }","typeGuard":null,"tryCatchPattern":"match workspace.find_commit(commit_id) {\n    Err(e) if e.to_string().contains(\"Found multiple matches\") => {\n        // pick the stack-scoped lookup instead\n        let c = stack.find_commit(commit_id)?;\n    }\n    other => other?,\n}","preventionTips":["Run `but status` to check for the same commit in multiple stacks.","Avoid cherry-picking the same commit into several managed stacks.","Refresh the workspace index after operations that duplicate commits."],"tags":["git","commit-lookup","ambiguity"],"backgroundTag":"invalid-identifier","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}