alibaba/open-code-review · error
%s value %q is not a valid commit ref: %s
Error message
%s value %q is not a valid commit ref: %s
What it means
validateReviewRefs verifies each non-empty --from/--to/--commit value with `git rev-parse --verify --end-of-options <ref>^{commit}`. When git rejects the ref and prints a message, that message is surfaced as "%s value %q is not a valid commit ref: <git output>". This means the value is syntactically fine but git cannot resolve it to a commit.
Source
Thrown at cmd/opencodereview/review_cmd.go:480
refs := []struct {
flag string
ref string
}{
{"--from", opts.from},
{"--to", opts.to},
{"--commit", opts.commit},
}
for _, item := range refs {
if item.ref == "" {
continue
}
if strings.HasPrefix(item.ref, "-") {
return fmt.Errorf("%s value %q is not a valid git ref: refs must not start with '-'", item.flag, item.ref)
}
if out, err := runGitCmd(repoDir, "rev-parse", "--verify", "--end-of-options", item.ref+"^{commit}"); err != nil {
msg := strings.TrimSpace(string(out))
if msg != "" {
return fmt.Errorf("%s value %q is not a valid commit ref: %s", item.flag, item.ref, msg)
}
return fmt.Errorf("%s value %q is not a valid commit ref", item.flag, item.ref)
}
}
return nil
}
func runPreviewContext(ctx context.Context, cc *commonContext, opts reviewOptions, out io.Writer) error {
preview, err := agent.Preview(ctx, agent.Args{
RepoDir: cc.RepoDir,
From: opts.from,
To: opts.to,
Commit: opts.commit,
FileFilter: cc.FileFilter,
GitRunner: cc.GitRunner,
})
if err != nil {
return fmt.Errorf("preview failed: %w", err)View on GitHub (pinned to 5cf97d0d15)
Solutions
- Read the trailing git message — it names the exact resolution problem (unknown revision, ambiguous ref, etc.).
- Run `git rev-parse --verify <ref>^{commit}` yourself to confirm the ref resolves.
- `git fetch` to bring in remote refs that are missing locally.
- Use the full 40-char SHA to disambiguate short/ambiguous refs.
Example fix
// before ocr review --from feature-x # deleted locally // after git fetch origin && ocr review --from origin/feature-x --to HEAD
Defensive patterns
Strategy: validation
Validate before calling
if out, err := exec.Command("git", "rev-parse", "--verify", ref+"^{commit}").Output(); err != nil {
return fmt.Errorf("ref %q does not resolve to a commit", ref)
} Try / catch
if err := validateReviewRefs(repoDir, opts); err != nil {
var refErr *RefError
if errors.As(err, &refErr) {
fmt.Fprintf(os.Stderr, "check %s: try git fetch\n", refErr.Flag)
}
return err
} Prevention
- git fetch before reviewing remote branches.
- Prefer full SHAs over ambiguous short refs.
- Re-verify refs after rebase/reset operations.
When it happens
Trigger: Passing a branch/tag/SHA that does not exist in the repo, an ambiguous ref, or a tree/annotated-tag-only expression to --from/--to/--commit.
Common situations: Reviewing after a rebase removed the commit; typo in a SHA; ref exists only on a remote not fetched locally; using a branch name deleted from origin.
Related errors
- %s value %q is not a valid commit ref
- preview failed: %w
- git log failed: %w
- resolve current input identity: %w
- %s is not a git repository, code review requires a valid git
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/48cf20af19b72f70.
Report an issue: GitHub.