如何在不在本地克隆存储库的情况下获取提交列表

问题描述 投票:1回答:1

我现有的代码

//clone repo
File localPath = File.createTempFile("TestGitRepository", "");
localPath.delete();
private Repository repo;
Git git = Git.cloneRepository()
                    .setCredentialsProvider(credentials)
                    .setURI(url)
                    .setBranch(branch)
                    .setDirectory(localPath)
                    .call();

                repo = git.getRepository();

//get commit by using cloned repo
 try (Git git = new Git(repo)) {
   Iterable<RevCommit> logs = git.log().call();
   for (RevCommit rev : logs) {
    System.out.println("Commit: " + rev + ", name: " + rev.getName() + ", id: " + rev.getId().getName());

        }
    } catch (Exception e) {
        System.out.println("Exception: {}"+e);
    }

我能够通过克隆存储库来获取提交列表,我想避免克隆存储库。如果有办法,请分享一些链接,如果需要,还建议我额外的库。

java jgit
1个回答
0
投票

在这里你可以简单地使用git命令获取git日志而不需要git副本,

git log -- <git http url

例如git log -- [email protected]/twitter/bootstrap.git

© www.soinside.com 2019 - 2024. All rights reserved.