2

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.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
  • I see you are new to SO. If you feel an answer solved the problem, please mark it as 'accepted' by clicking the green check mark. This helps keep the focus on older posts which still don't have answers – Rüdiger Herrmann Feb 18 '18 at 15:50
  • Thanks for the reminder, I will spend some time to give a try with the provided suggestion, and will follow this rule once it proves to be working for me. – shen xieyin Feb 20 '18 at 00:49

1 Answers1

2

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?

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79