【问题标题】:How to read Git notes using JGit given a commit-sha给定 commit-sha 如何使用 JGit 阅读 Git 笔记
【发布时间】:2018-02-20 09:20:08
【问题描述】:

我正在尝试使用 JGit 从存储库中特定提交的自定义 ref refs/notes/abcd 读取 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()

【问题讨论】:

    标签: java git jgit git-notes


    【解决方案1】:

    使用RevWalk,可以解析对象id,并将生成的RevCommit传递给ShowNoteCommand

    例如:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 2017-06-12
    • 2012-11-06
    • 2015-10-09
    • 2012-09-05
    • 2021-09-25
    相关资源
    最近更新 更多