gitbutlerapp/gitbutler · error

No oplog entry found matching SHA

Error message

No oplog entry found matching SHA: {sha_prefix}

What it means

show_oplog throws this when a partial SHA supplied via `--since` cannot be resolved with rev_parse_single against the repository. GitButler rejects unresolvable prefixes so it does not silently filter the oplog from an unknown point.

Solutions

  1. Run `but oplog` without --since to list available snapshot SHAs and copy a valid one
  2. Verify the prefix resolves locally with `git rev-parse <sha_prefix>`
  3. Fetch or restore missing objects if the SHA refers to history that was garbage-collected

Example fix

// before
but oplog --since abc12x  // typo'd prefix
// after
but oplog                # list valid SHAs
but oplog --since abc123
Defensive patterns

Strategy: validation

Validate before calling

// resolve the SHA prefix with git before passing --since
const sha = execSync(`git rev-parse ${prefix}`).toString().trim();
if (!/^[0-9a-f]{40}$/.test(sha)) throw new Error(`Invalid SHA: ${prefix}`);
await runBut(['oplog', '--since', sha]);

Type guard

function isValidShaPrefix(s: string): boolean {
  return /^[0-9a-f]{4,40}$/.test(s);
}

Try / catch

try {
  await runBut(['oplog', '--since', prefix]);
} catch (e) {
  if (/No oplog entry found matching SHA/.test(e.message)) {
    console.error('Unknown SHA; run `but oplog` to list valid snapshots');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `but oplog --since <sha>` where the SHA prefix is a typo, refers to an object not present locally (unfetched GC'd object), or is not a valid revision syntax.

Common situations: Copy-pasting a SHA from another machine, referencing an oplog snapshot after history pruning/garbage collection, or truncating SHAs below the unique-prefix length.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at crates/but/src/command/legacy/oplog.rs:43

        }
    }
}

pub(crate) fn show_oplog(
    ctx: &mut but_ctx::Context,
    out: &mut OutputChannel,
    since: Option<&str>,
    filter: Option<OplogFilter>,
) -> anyhow::Result<()> {
    // Convert filter to include_kind parameter for the API
    let include_kind = filter.map(|f| f.to_include_kinds());

    // Resolve partial SHA to full SHA using rev_parse if provided
    let since_sha = if let Some(sha_prefix) = since {
        let repo = ctx.repo.get()?;
        let resolved = repo
            .rev_parse_single(sha_prefix)
            .map_err(|_| anyhow::anyhow!("No oplog entry found matching SHA: {sha_prefix}"))?;
        Some(resolved.detach())
    } else {
        None
    };

    let snapshots = but_api::legacy::oplog::snapshots_iter(ctx, since_sha, None, include_kind)?
        .take(20)
        .collect::<anyhow::Result<Vec<_>>>()?;

    if snapshots.is_empty() {
        if let Some(out) = out.for_json() {
            out.write_value(&snapshots)?;
        } else if let Some(out) = out.for_human() {
            writeln!(out, "No operations found in history.")?;
        }
        return Ok(());
    }

View on GitHub (pinned to 58e5313667)