简体   繁体   English

如何使用 JGit 获取标签之间的提交列表?

[英]How to obtain commit list between tags with JGit?

Suppose that given two tags as input, like "v5.8.0.202005061305-m2" and "v5.7.0.202003090808-r".假设给定两个标签作为输入,例如“v5.8.0.202005061305-m2”和“v5.7.0.202003090808-r”。

Is there a way to obtain the commit list between two tags with JGit?有没有办法用 JGit 获取两个标签之间的提交列表?

I know GitHub has that functionality as you can compare two tags and see all the commits in between but can we do the same with JGit?我知道 GitHub 具有该功能,因为您可以比较两个标签并查看其间的所有提交,但是我们可以用 JGit 做同样的事情吗?

The LogCommand has an addRange method to specify the commits you are interested in. LogCommand有一个addRange方法来指定您感兴趣的提交。

This is an example that resolves the tag names to commit IDs and then uses the LogCommand to list all commits in that range.这是一个将标签名称解析为提交 ID,然后使用LogCommand列出该范围内的所有提交的示例。

Git git = ...
Ref tag1 = git.getRepository().exactRef("refs/tags/tag1");
Ref tag2 = git.getRepository().exactRef("refs/tags/tag2");
Iterable<RevCommit> commits = git.log().addRange(tag1.getPeeledObjectId(), tag2.getPeeledObjectId());
for(RevCommit : commits ) {
  ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM