{"record":{"id":"48cf20af19b72f70","repo":"alibaba/open-code-review","slug":"s-value-q-is-not-a-valid-commit-ref-s","errorCode":null,"errorMessage":"%s value %q is not a valid commit ref: %s","messagePattern":"(.+?) value %q is not a valid commit ref: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/review_cmd.go","lineNumber":480,"sourceCode":"\trefs := []struct {\n\t\tflag string\n\t\tref  string\n\t}{\n\t\t{\"--from\", opts.from},\n\t\t{\"--to\", opts.to},\n\t\t{\"--commit\", opts.commit},\n\t}\n\tfor _, item := range refs {\n\t\tif item.ref == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tif strings.HasPrefix(item.ref, \"-\") {\n\t\t\treturn fmt.Errorf(\"%s value %q is not a valid git ref: refs must not start with '-'\", item.flag, item.ref)\n\t\t}\n\t\tif out, err := runGitCmd(repoDir, \"rev-parse\", \"--verify\", \"--end-of-options\", item.ref+\"^{commit}\"); err != nil {\n\t\t\tmsg := strings.TrimSpace(string(out))\n\t\t\tif msg != \"\" {\n\t\t\t\treturn fmt.Errorf(\"%s value %q is not a valid commit ref: %s\", item.flag, item.ref, msg)\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"%s value %q is not a valid commit ref\", item.flag, item.ref)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc runPreviewContext(ctx context.Context, cc *commonContext, opts reviewOptions, out io.Writer) error {\n\tpreview, err := agent.Preview(ctx, agent.Args{\n\t\tRepoDir:    cc.RepoDir,\n\t\tFrom:       opts.from,\n\t\tTo:         opts.to,\n\t\tCommit:     opts.commit,\n\t\tFileFilter: cc.FileFilter,\n\t\tGitRunner:  cc.GitRunner,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"preview failed: %w\", err)","sourceCodeStart":462,"sourceCodeEnd":498,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/review_cmd.go#L462-L498","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nocr review --from feature-x  # deleted locally\n// after\ngit fetch origin && ocr review --from origin/feature-x --to HEAD","handlingStrategy":"validation","validationCode":"if out, err := exec.Command(\"git\", \"rev-parse\", \"--verify\", ref+\"^{commit}\").Output(); err != nil {\n    return fmt.Errorf(\"ref %q does not resolve to a commit\", ref)\n}","typeGuard":null,"tryCatchPattern":"if err := validateReviewRefs(repoDir, opts); err != nil {\n    var refErr *RefError\n    if errors.As(err, &refErr) {\n        fmt.Fprintf(os.Stderr, \"check %s: try git fetch\\n\", refErr.Flag)\n    }\n    return err\n}","preventionTips":["git fetch before reviewing remote branches.","Prefer full SHAs over ambiguous short refs.","Re-verify refs after rebase/reset operations."],"tags":["git","ref-validation"],"backgroundTag":"invalid-git-ref","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}