我有一个带有一些测试提交的存储库(全部在默认分支上)。使用 JGit log 命令,我可以看到这些提交(例如):
RepositoryBuilder builder = new RepositoryBuilder();
Repository repository = builder.setWorkTree("/tmp/myworkingdir").readEnvironment().findGitDir().build();
Git git = new Git(repository);
for (RevCommit commit : git.log().call()) {
System.out.println("commit: " + commit.getId());
}
结果:
commit: commit f34a848371ff334b2e85aa16fbf9b871d028b443 1371652639 ----sp
commit: commit 33603f8c1c47712d45eb0db4b1827bbd113c2428 1371652639 ----sp
commit: commit d52bd5c768263a957d99975f5482020ffc3434d5 1371652639 ----sp
但是,当我尝试从 String SHA1 获取 RevCommit 时,它在此代码段的最后一行失败:
ObjectId revid = repository.resolve("33603f8c1c47712d45eb0db4b1827bbd113c2428");
RevWalk revWalk = new RevWalk(repository);
RevCommit commit = revWalk.parseCommit(revid);
例外:
org.eclipse.jgit.errors.MissingObjectException: Missing unknown 33603f8c1c47712d45eb0db4b1827bbd113c2428
at org.eclipse.jgit.storage.file.WindowCursor.open(WindowCursor.java:126)
at org.eclipse.jgit.lib.ObjectReader.open(ObjectReader.java:229)
at org.eclipse.jgit.revwalk.RevWalk.parseAny(RevWalk.java:817)
at org.eclipse.jgit.revwalk.RevWalk.parseCommit(RevWalk.java:730)
我究竟做错了什么 ?
解决方案 Repository 的 Init 在访问部分是错误的..