Reputation: 53
Suppose that given two tags as input, like "v5.8.0.202005061305-m2" and "v5.7.0.202003090808-r".
Is there a way to obtain the commit list between two tags with 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?
Upvotes: 2
Views: 538
Reputation: 20985
The LogCommand
has an addRange
method to specify the commits you are interested in.
This is an example that resolves the tag names to commit IDs and then uses the LogCommand
to list all commits in that range.
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 ) {
...
}
Upvotes: 1