Java 如何在不克隆本地存储库的情况下获取提交列表
我现有的代码Java 如何在不克隆本地存储库的情况下获取提交列表,java,jgit,Java,Jgit,我现有的代码 //clone repo File localPath = File.createTempFile("TestGitRepository", ""); localPath.delete(); private Repository repo; Git git = Git.cloneRepository() .setCredentialsProvider(credentials) .setURI(url)
//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);
}
//克隆repo
File localPath=File.createTempFile(“TestGitRepository”,”);
delete();
私有存储库回购;
Git Git=Git.cloneRepository()
.setCredentialsProvider(凭据)
.setURI(url)
.setBranch(分行)
.setDirectory(本地路径)
.call();
repo=git.getRepository();
//使用克隆的repo获取提交
try(吉特=新吉特(回购)){
Iterable logs=git.log().call();
for(RevCommit rev:logs){
System.out.println(“提交:“+rev+”,名称:“+rev.getName()+”,id:“+rev.getId().getName()”);
}
}捕获(例外e){
System.out.println(“异常:{}”+e);
}
我可以通过克隆存储库来获取提交列表,我希望避免克隆存储库。如果有办法的话,请与我分享一些链接,如果需要,还可以建议我添加库。在这里,您只需使用git命令获取git日志,而无需git副本
git log--这个问题已经问了8个月了。
如果其他人也在寻找相同的答案,我将向您展示如何在不克隆标签列表的情况下获取标签列表。
在JGit中,可以使用lsRemoteRepository方法
Git.lsRemoteRepository().setRemote(gitUrl).setTags(true).call()
使用此方法,您可以获取远程响应中的所有标签不可能的可能副本。您至少需要获取您感兴趣的远程分支。也许有一种方法可以实现不包含任何文件内容的真正“精简”克隆?我在线程“main”org.eclipse.jgit.api.errors.NoHeadException中遇到错误异常:不存在头,并且在org.eclipse.jgit.api.LogCommand.call(LogCommand.java:150)中未指定明确的起始版本位于com.nirmata.environments.git.JGitRepositoryController.getCommissions(JGitRepositoryController.java:127)位于com.nirmata.environments.git.JGitRepositoryController.main(JGitRepositoryController.java:164)