【问题标题】:How to read all the commits of a public git repository using EGIT?如何使用 EGIT 读取公共 git 存储库的所有提交?
【发布时间】:2018-08-06 03:49:32
【问题描述】:

我正在使用 EGit API 来读取远程存储库。我的用例是读取任何公共 git 存储库的所有提交。 EGit 可以吗?

以下是我读取所有存储库的代码:

GitHubClient client = new GitHubClient();
    client.setCredentials("xxx.xx.xx@gmail.com", "********");

    RepositoryService service = new RepositoryService(client);

    List<Repository> repositories = service.getRepositories();

    for (int i = 0; i < repositories.size(); i++)
    {
        Repository get = repositories.get(i);
        System.out.println("Repository Name: " + get.getName());
    }

为了阅读我使用的提交:

CommitService commitService = new CommitService(client);
    for (RepositoryCommit commit : commitService.getCommits(repository)) {
        System.out.println(commit.getCommit().getMessage());
    }

这仅列出属于我的存储库。但是假设我想从一个公共仓库中读取所有提交,比如https://github.com/eclipse/jgit

EGit 可以吗?

【问题讨论】:

    标签: java eclipse git repository egit


    【解决方案1】:

    EGit 是 Eclipse 的 Git 集成。要以编程方式访问 Git 存储库,请使用 JGit。您的代码 sn-ps 指的是 EGit 也提供的 GitHub API,用于检查托管在 GitHub 上的存储库。

    要访问任意 Git 存储库(不仅仅是 GitHub 上的存储库)的历史记录,您需要先克隆它。例如:

    Git.cloneRepository()
      .setURI( "https://github.com/eclipse/jgit.git" )
      .setDirectory( "path/to/local/repo" )
      .call();
    

    关于如何使用 JGit 克隆存储库的详细说明可以在这里找到:http://www.codeaffine.com/2015/11/30/jgit-clone-repository/

    现在您可以使用LogCommand 列出本地存储库的提交。示例见此处:Retrieving Commit Message Log from Git Using JGit

    【讨论】:

    • 所以不克隆存储库是不可能的?
    • 如果您只对 GitHub 存储库感兴趣,那么您可以通过 GitHub ReST API 获得所需的信息。请参阅 [文档] (developer.github.com/v3) 以查看是否提供了所需信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-12
    • 2018-04-16
    • 2019-10-30
    • 2010-10-11
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多