{"record":{"id":"92c0e273e7be432f","repo":"theonedev/onedev","slug":"commit-not-found","errorCode":null,"errorMessage":"Commit not found","messagePattern":"Commit not found","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/RepositoryResource.java","lineNumber":302,"sourceCode":"\n\t\tvar fieldSet = EnumSet.noneOf(LogCommand.Field.class);\n\t\tfieldSet.addAll(fields.stream().map(LogCommand.Field::valueOf).collect(toList()));\n\t\t\n\t\treturn gitService.log(project, options, fieldSet);\n    }\n\t\n\t@Api(order=86, description=\"Get specified commit\")\n\t@Path(\"/{projectId}/commits/{commitHash}\")\n\t@GET\n    public LogCommit getCommit(\n\t\t\t@PathParam(\"projectId\") Long projectId,\n\t\t\t@PathParam(\"commitHash\") @Api(example=\"8cbec3d9eda2050a4ca0676767be3b6bf20251b8\") String commitHash,\n\t\t\t@QueryParam(\"field\") @Api(exampleProvider = \"getFieldsExample\", description = \"Fields to return. Unspecified fields will return as null in returned commit object\") List<String> fields) {\n\t\tvar commits = queryCommits(projectId, \"commit(\" + commitHash + \")\", 1, fields);\n\t\tif (!commits.isEmpty())\n\t\t\treturn commits.iterator().next();\n\t\telse\n\t\t\tthrow new NotFoundException(\"Commit not found\");\n    }\n\n\t@SuppressWarnings(\"unused\")\n\tprivate static List<String> getFieldsExample() {\n\t\treturn EnumSet.allOf(LogCommand.Field.class).stream().map(Enum::name).collect(toList());\n\t}\n\t\n\t@Api(order=90, description=\"Get children of specified directory\")\n\t@Path(\"/{projectId}/directories/{revisionAndDirectory:.*}\")\n\t@GET\n\tpublic List<DirectoryChild> getDirectory(\n\t\t\t@PathParam(\"projectId\") Long projectId, \n\t\t\t@PathParam(\"revisionAndDirectory\") @NotEmpty @Api(example=\"some-branch-or-tag/path/to/directory\") String revisionAndDirectory) {\n\t\tProject project = projectService.load(projectId);\n\t\tif (!SecurityUtils.canReadCode(project)) {\n\t\t\tthrow new UnauthorizedException();\n\t\t}\n","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/RepositoryResource.java#L284-L320","documentation":"RepositoryResource.getCommit resolves a single commit by delegating to queryCommits with query \"commit(<hash>)\" and count 1. If the query returns no commits — the hash does not exist in the repository — it throws a NotFoundException with message \"Commit not found\" (HTTP 404).","triggerScenarios":"GET .../commits/{commitHash} with a hash that is not reachable in the project's repository: a wrong/truncated hash, a hash from a fork or another project, or a commit on a force-pushed-away branch.","commonSituations":"Cross-project lookups (commit exists in fork, not in this project); history rewritten by force-push so old hashes vanish; typos or copying a short hash that was later rebased.","solutions":["Verify the commit hash exists in this specific project (git cat-commit or the UI) before calling the API.","Confirm you are querying the correct projectId — commits are project-scoped.","Use the full 40-character hash if a shortened hash is ambiguous or mis-copied.","If the commit was force-pushed away, restore it via a ref or look it up in the original repository."],"exampleFix":"// before: hash from a different repo\ncurl .../projects/42/commits/deadbeef  -> 404 Commit not found\n\n// after: hash verified against project 42\ncurl .../projects/42/commits/8cbec3d9eda2050a4ca0676767be3b6bf20251b8","handlingStrategy":"try-catch","validationCode":"// resolve the ref/hash first if your client has Git access\ngit rev-parse --verify <hash>^{commit} || echo \"commit not present locally\"","typeGuard":"function isFullHash(s) { return /^[0-9a-f]{40}$/.test(s); }","tryCatchPattern":"try {\n  return getCommit(projectId, hash, fields);\n} catch (e) {\n  if (isNotFound(e)) return null; // commit not in this project — handle upstream\n  throw e;\n}","preventionTips":["Always scope commit lookups to the same projectId the hash came from.","Use full 40-char hashes from API responses rather than user-pasted short hashes.","Treat 404 as 'not in this repo' — check forks or other projects."],"tags":["rest-api","git","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}