如何使用 EGIT 读取 public git 存储库的所有提交?

How to read all the commits of a public git repository using EGIT?

我正在使用 EGit API 读取远程存储库。我的用例是读取任何 public 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());
    }

这只列出了属于我的存储库。但是假设我想从 public 回购协议中读取所有提交,例如 https://github.com/eclipse/jgit

EGit 可以吗?

EGit 是 Eclipse 的 Git 集成。要以编程方式访问 Git 个存储库,请使用 JGit。您的代码片段引用了 GitHub API,它也由 EGit 提供,用于检查 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