nikivdev/code · error

commit not found: {}

Error message

commit not found: {}

What it means

Thrown by `resolve_full_hash` when `git rev-parse <commit_ref>` exits non-zero, i.e. git cannot resolve the given reference to a commit. Used by `unmark_top_commit`, so it typically means a stored 'top' entry references a commit that no longer exists or was never valid.

Source

Thrown at src/commits.rs:480

    Ok(Some(CommitEntry {
        hash,
        full_hash,
        subject,
        relative_time,
        author,
        has_ai_metadata,
        is_top: true,
        display,
    }))
}

fn resolve_full_hash(commit_ref: &str) -> Result<String> {
    let output = Command::new("git")
        .args(["rev-parse", commit_ref])
        .output()
        .context("failed to run git rev-parse")?;
    if !output.status.success() {
        bail!("commit not found: {}", commit_ref);
    }
    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
}

fn load_top_entries() -> Result<Vec<TopEntry>> {
    let path = top_file_path()?;
    if !path.exists() {
        return Ok(Vec::new());
    }
    let content = fs::read_to_string(&path).context("failed to read top commits")?;
    let mut entries = Vec::new();
    for line in content.lines() {
        let trimmed = line.trim();
        if trimmed.is_empty() {
            continue;
        }
        let (hash, label) = match trimmed.split_once('\t') {
            Some((hash, label)) => (hash.to_string(), Some(label.to_string())),

View on GitHub (pinned to a747e741ae)

Solutions

  1. Run `git rev-parse <ref>` manually to confirm the ref is invalid
  2. Look up the intended commit via `git log --oneline` or `git reflog` and use its current hash
  3. Remove or fix the stale entry in the top file so unmark no longer references it
  4. If the commit was rebased away, find its equivalent in the new history (git log --all --grep)

Example fix

// before
unmark_top_commit("a1b2c3d") // commit not found: a1b2c3d
// after
let valid = String::from_utf8_lossy(
    &Command::new("git").args(["rev-parse", "--verify", "a1b2c3d^{commit}"],).output()?.stdout,
);
if valid.trim().is_empty() { eprintln!("ref not found, skipping unmark"); return Ok(()); }
Defensive patterns

Strategy: validation

Validate before calling

// verify the ref resolves before unmarking
let ok = Command::new("git")
    .args(["rev-parse", "--verify", "--quiet", &format!("{}^{{commit}}", commit_ref)])
    .output()?
    .status.success();
if !ok {
    eprintln!("{commit_ref} no longer exists; cleaning stale entry");
    return Ok(());
}

Type guard

fn commit_exists(commit_ref: &str) -> bool {
    Command::new("git")
        .args(["rev-parse", "--verify", "--quiet", &format!("{}^{{commit}}", commit_ref)])
        .output()
        .map(|o| o.status.success())
        .unwrap_or(false)
}

Try / catch

match unmark_top_commit(commit_ref) {
    Err(e) if e.to_string().starts_with("commit not found") => {
        eprintln!("{commit_ref} is gone (rebase/reset?); removing stale top entry");
        remove_stale_top_entry(commit_ref)?;
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling unmark_top_commit with a commit ref that is misspelled, was garbage-collected, belongs to a pruned branch, or is an abbreviated hash whose object no longer exists.

Common situations: Commit removed by `git rebase`/`reset`/`filter-branch` after being marked, stale top-file entries after cloning a fresh repo, typo'd short hash, or ref names differing between local and remote.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/fe24750e16df1d02. Report an issue: GitHub.