我想使用Eclipse的JGit库查找特定分支的第一次提交。例如,如果我有
master -- a -- c -- d -- e
\
feature b -- f -- g -- h
\
another j -- k -- l
// findBranchRoot() is the magic method we want to create
repository.resolve("feature").findBranchRoot().getId(); // this would return b
repository.resolve("another").findBranchRoot().getId(); // this would return j
有人知道该怎么做吗?
如果first commit表示分支的最新/最新提交,则可以使用ObjectId
返回的Repository::resolve
来获得带有RevCommit
的RevWalk
(JGit的提交对象表示) ]:
ObjectId commitId = repository.resolve("refs/heads/feature");
try(RevWalk revWalk = new RevWalk(repository)) {
RevCommit commit = revWalk.parseCommit(commitId);
}
我建议将完全合格的参考传递给resolve
(如示例中所示)。否则,您可能会得到AmbiguousObjectException
或该方法返回具有相同短名的注释或标签。