shen xieyin
shen xieyin

Reputation: 25

How to log the commits between two release tags with JGit

I have one case which is for example to run git command like

$ git log 1.0.201802090918...1.0.201802071240" 

to get a differed commits list between release tag 1.0.201802090918 and 1.0.201802071240 under my repo. So I wonder how to code with JGit to gain the same here.

Upvotes: 2

Views: 1024

Answers (1)

Rüdiger Herrmann
Rüdiger Herrmann

Reputation: 20985

The LogCommand allows to specify the range of commits that it will include. The range need to be given as ObjectIds. And if tags mark the start and end points, the commit IDs that they reference need to be extracted first.

The snippet below illustrates the necessary steps:

ObjectId from = repo.resolve("refs/tags/start-tag");
ObjectId to = repo.resolve("refs/tags/end-tag");
git.log().addRange(from, to).call();

If annotated tags are used, they may have to be unpeeled first as described here: what is the difference between getPeeledObjectId() and getObjectId() of Ref Object?

Upvotes: 2

Related Questions