{"record":{"id":"deb95cc5a58f2b0d","repo":"golang/go","slug":"revision-does-not-exist-locally-s","errorCode":null,"errorMessage":"revision does not exist locally: %s","messagePattern":"revision does not exist locally: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modfetch/codehost/git.go","lineNumber":545,"sourceCode":"\tif !didStatLocal {\n\t\tif info, err := r.statLocal(ctx, rev, hash); err == nil {\n\t\t\ttag, fromTag := strings.CutPrefix(ref, \"refs/tags/\")\n\t\t\tif fromTag && !slices.Contains(info.Tags, tag) {\n\t\t\t\t// The local repo includes the commit hash we want, but it is missing\n\t\t\t\t// the corresponding tag. Add that tag and try again.\n\t\t\t\t_, err := r.runGit(ctx, \"git\", \"tag\", \"--end-of-options\", tag, hash)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tr.localTags.Store(tag, true)\n\t\t\t\treturn r.statLocal(ctx, rev, ref)\n\t\t\t}\n\t\t\treturn info, err\n\t\t}\n\t}\n\n\tif r.local { // at this point, we have determined that we need to fetch rev, fail early if local only mode.\n\t\treturn nil, fmt.Errorf(\"revision does not exist locally: %s\", rev)\n\t}\n\n\t// If we know a specific commit we need and its ref, fetch it.\n\t// We do NOT fetch arbitrary hashes (when we don't know the ref)\n\t// because we want to avoid ever importing a commit that isn't\n\t// reachable from refs/tags/* or refs/heads/* or HEAD.\n\t// Both Gerrit and GitHub expose every CL/PR as a named ref,\n\t// and we don't want those commits masquerading as being real\n\t// pseudo-versions in the main repo.\n\tif r.fetchLevel <= fetchSome && ref != \"\" && hash != \"\" {\n\t\tr.fetchLevel = fetchSome\n\t\tvar refspec string\n\t\tif ref == \"HEAD\" {\n\t\t\t// Fetch the hash but give it a local name (refs/dummy),\n\t\t\t// because that triggers the fetch behavior of creating any\n\t\t\t// other known remote tags for the hash. We never use\n\t\t\t// refs/dummy (it's not refs/tags/dummy) and it will be\n\t\t\t// overwritten in the next command, and that's fine.","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modfetch/codehost/git.go#L527-L563","documentation":"Thrown by gitRepo.Stat when operating in local-only mode (r.local == true) and the requested revision cannot be found via local git operations after all local lookup paths are exhausted. In local mode, the tool will not perform network fetches, so a missing revision is a hard failure.","triggerScenarios":"Stat(ctx, rev) on a gitRepo opened with local=true (e.g. a replace directive pointing at a local path) where rev is a tag, branch, or hash that does not exist in that local repo. The method tried statLocal and local tags already.","commonSituations":"A local replace directive pointing at a checkout that doesn't have the requested tag/branch; the local repo is shallow and missing the commit; the revision string is misspelled; the local checkout is behind upstream.","solutions":["Verify the revision exists locally: 'cd <local_path> && git rev-parse <rev>'.","Fetch/update the local repo: 'cd <local_path> && git fetch --all && git checkout <rev>'.","Check for typos in the version string in go.mod.","If a shallow clone, deepen it: 'git fetch --unshallow'."],"exampleFix":"# before: local replace missing the tag\nreplace example.com/mod => ./local-mod\n# go.mod requires v1.5.0 but ./local-mod doesn't have it\ncd ./local-mod && git fetch --tags\ngo mod tidy\n# after\ngo build ./...","handlingStrategy":"validation","validationCode":"// Before relying on a local replace, verify the revision exists\nfunc validateLocalRev(repoDir, rev string) error {\n    cmd := exec.Command(\"git\", \"-C\", repoDir, \"rev-parse\", \"--verify\", rev)\n    if out, err := cmd.CombinedOutput(); err != nil {\n        return fmt.Errorf(\"revision %q not found in %s: %s\", rev, repoDir, out)\n    }\n    return nil\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Keep local replace targets fetched and checked out to the required ref.","Run 'git fetch --tags' on local replace directories before building.","Validate local revisions in pre-build scripts with 'git rev-parse --verify'.","Avoid shallow clones for local replace targets; use full clones."],"tags":["git","local-mode","revision-resolution","missing-revision","replace-directive"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}