0

我正在尝试refs/notes/abcd使用 JGit 从存储库中特定提交的自定义引用中读取 Git Notes 信息

这是我尝试过的:

Repository repository = repositoryManager.openRepository(repoName);
Git git = new Git(repository);
ObjectId oid = repository.resolve("5740b142a7b5f66768a2d904b267dccaef1a095f");
Note note = git.notesShow().setNotesRef("refs/notes/abcd").setObjectId(oid).call();
ObjectLoader loader = repository.open(note.getData());
byte[] data = loader.getBytes();
System.out.println(new String(data, "utf-8"));

我收到以下编译错误:

错误:不兼容的类型:org.eclipse.jgit.lib.ObjectId 无法转换为 org.eclipse.jgit.revwalk.RevObject

给定 commit-sha 字符串,如何将RevObject变量传递给 Git ?setObjectId()

4

1 回答 1

1

With a RevWalk, the object id can be parsed and the resulting RevCommit can be passed to the ShowNoteCommand.

For example:

RevCommit commit;
try( RevWalk revWalk = new RevWalk( repository ) ) {
  commit = revWalk.parseCommit( oid );
}

git.notesShow().setObjectId( commit )...
于 2017-09-12T08:33:39.357 回答