gastownhall/beads · error

git returned invalid commit object ID %q

Error message

git returned invalid commit object ID %q

What it means

After `git rev-parse --verify --quiet <ref>^{commit}` succeeds, bd validates that the returned object ID is a hex string of the repository's expected hash length (SHA-1 = 40, SHA-256 = 64) before using it as a comparator. This error means git reported success but returned a value that is not a valid commit OID, indicating an unexpected git behavior or output parsing problem.

Source

Thrown at cmd/bd/worktree_cmd.go:1955

	output, err := git.output(
		ctx,
		executionRoot,
		"rev-parse",
		"--verify",
		"--quiet",
		"--end-of-options",
		refOrOID+"^{commit}",
	)
	if err != nil {
		return "", err
	}
	oid := strings.TrimSpace(string(output))
	hashLength, err := repositoryObjectIDLength(ctx, git, executionRoot)
	if err != nil {
		return "", err
	}
	if !isHexObjectID(oid, hashLength) {
		return "", fmt.Errorf("git returned invalid commit object ID %q", oid)
	}
	return strings.ToLower(oid), nil
}

func resolveUpstreamWorktreeComparator(
	ctx context.Context,
	git *worktreeRemovalGit,
	executionRoot string,
	target pinnedWorktreeTarget,
) (pinnedWorktreeComparator, error) {
	if target.branch == "" || target.detached {
		return pinnedWorktreeComparator{}, fmt.Errorf(
			"cannot verify unpushed commits: target is detached; use --merged-into <ref>",
		)
	}
	output, err := git.output(
		ctx,
		executionRoot,

View on GitHub (pinned to 71377f2769)

Solutions

  1. Check the repo's object format: `git rev-parse --show-object-format` and ensure it matches expectations (sha1 or sha256)
  2. Run `git rev-parse --verify <ref>^{commit}` manually and inspect the raw output
  3. Verify git integrity/version: `git --version`; upgrade if it is an unusual or patched build
  4. Run `git fsck` to detect corrupted refs producing garbage OIDs

Example fix

// before: repo in sha256 mode with mismatched tooling
$ git rev-parse --show-object-format
sha256
// after: ensure consistent object format (reinit/convert repo or update bd)
$ git init --object-format=sha1  # for new repos, or use a bd version supporting sha256
Defensive patterns

Strategy: validation

Validate before calling

// confirm the ref resolves to a hex OID of the expected length before calling bd
out, err := exec.Command("git", "rev-parse", "--verify", ref+"^{commit}").Output()
if err != nil {
	return fmt.Errorf("ref %q does not resolve to a commit", ref)
}
oid := strings.TrimSpace(string(out))
if len(oid) != 40 && len(oid) != 64 {
	return fmt.Errorf("unexpected OID length %d for %q", len(oid), ref)
}
if _, err := hex.DecodeString(oid); err != nil {
	return fmt.Errorf("non-hex OID %q", oid)
}

Type guard

func isHexObjectID(s string, length int) bool {
	if len(s) != length { return false }
	_, err := hex.DecodeString(s)
	return err == nil
}

Try / catch

_, err := bd.WorktreeRemove(name)
if err != nil && strings.Contains(err.Error(), "invalid commit object ID") {
	// check object format and git version, then retry or abort
	return diagnoseObjectFormat(name)
}

Prevention

When it happens

Trigger: `resolveWorktreeCommitOID` receives non-hex, wrong-length, or empty output from `git rev-parse` despite a zero exit code — e.g. a git build with unusual extensions output, locale-mangled output, or a hash-length mismatch between the repo's object format and what bd detected.

Common situations: Repositories configured for SHA-256 object format where the detected hash length disagrees; wrappers or aliases altering git output; corrupted ref files containing garbage that rev-parse echoes back; extremely old or patched git versions.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/1b869c69f632dc3f. Report an issue: GitHub.