{"record":{"id":"448c3c8e7ecf49a5","repo":"nikivdev/code","slug":"hash-is-not-a-valid-git-commit","errorCode":null,"errorMessage":"{hash} is not a valid git commit","messagePattern":"(.+?) is not a valid git commit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":7135,"sourceCode":"    let matches: Vec<_> = entries\n        .into_iter()\n        .filter(|entry| commit_queue_entry_matches(entry, hash))\n        .collect();\n\n    match matches.len() {\n        0 => bail!(\"No queued commit matches {}\", hash),\n        1 => Ok(matches.into_iter().next().unwrap()),\n        _ => bail!(\"Multiple queued commits match {}. Use a longer hash.\", hash),\n    }\n}\n\nfn resolve_git_commit_sha(repo_root: &Path, hash: &str) -> Result<String> {\n    let rev = format!(\"{hash}^{{commit}}\");\n    let sha = git_capture_in(repo_root, &[\"rev-parse\", \"--verify\", &rev])\n        .with_context(|| format!(\"{hash} is not a valid git commit\"))?;\n    let trimmed = sha.trim();\n    if trimmed.is_empty() {\n        bail!(\"{hash} is not a valid git commit\");\n    }\n    Ok(trimmed.to_string())\n}\n\nfn queue_existing_commit_for_approval(\n    repo_root: &Path,\n    hash: &str,\n    mark_reviewed: bool,\n) -> Result<CommitQueueEntry> {\n    let commit_sha = resolve_git_commit_sha(repo_root, hash)?;\n    let branch = git_capture_in(repo_root, &[\"rev-parse\", \"--abbrev-ref\", \"HEAD\"])\n        .unwrap_or_else(|_| \"unknown\".to_string())\n        .trim()\n        .to_string();\n    let message = git_capture_in(repo_root, &[\"log\", \"-1\", \"--format=%s\", &commit_sha])\n        .unwrap_or_default()\n        .trim()\n        .to_string();","sourceCodeStart":7117,"sourceCodeEnd":7153,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L7117-L7153","documentation":"resolve_git_commit_sha() runs `git rev-parse --verify <hash>^{commit}` inside the repo. If the command fails, or the returned SHA is empty, it throws this error indicating the supplied string is not a resolvable git commit in this repository. The git stderr is attached as context.","triggerScenarios":"Passing a hash that does not exist locally (not fetched), a branch/tag name that isn't a commit, a mistyped hash, or an abbreviated hash too short for git to resolve unambiguously.","commonSituations":"Referencing a commit from a remote that hasn't been fetched, typos in the hash, using a tag that was deleted, or running in a shallow clone where the commit is missing.","solutions":["Run `git rev-parse --verify <hash>^{commit}` yourself to see git's own error","Run `git fetch --all` if the commit may exist on a remote","Correct the hash typo or use the full 40-char SHA from `git log`","Check you are in the right repository/clone containing the commit"],"exampleFix":"// before (shell)\nf commit approve deadbeef   # unknown locally\n// after (shell)\ngit fetch --all && git rev-parse --verify deadbeef^{commit} && f commit approve deadbeef","handlingStrategy":"validation","validationCode":"use std::process::Command;\nfn commit_exists(repo: &std::path::Path, hash: &str) -> bool {\n    Command::new(\"git\")\n        .current_dir(repo)\n        .args([\"rev-parse\", \"--verify\", &format!(\"{hash}^{{commit}}\")])\n        .output()\n        .map(|o| o.status.success())\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = tool.resolve_commit_sha(repo, hash) {\n    if e.to_string().contains(\"is not a valid git commit\") {\n        let _ = Command::new(\"git\").current_dir(repo).args([\"fetch\", \"--all\"]).status();\n        // then retry or surface guidance to the user\n    } else { return Err(e.into()); }\n}","preventionTips":["`git fetch --all` before referencing remote commits","Validate refs with `git rev-parse --verify` before tooling calls","Use full 40-char SHAs in automation","Watch for shallow clones (--depth) missing history"],"tags":["git","invalid-input","rev-parse"],"backgroundTag":"invalid-git-ref","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}