I need to create a history file that details all tags and for each tag, all its commits.
I've tried to call getTags()
on the repository object and use those object id's, but they are not commit id's.
I also tried to use getAllRefsByPeeledObjectId()
on the repository and that does bring back commits but I can't associate them to tags.
Any ideas?
To get a list of tags you can either use
Repository#getTags()
or theListTagCommand
.There are annotated and unannotated tags in Git. While unannotated tags directly point to the commit they were placed on, an annotated tag points to a git object that holds - among other meta data like a message - the commit-id.
The learning test below ilustrates this:
In JGit, an annotated tag is represented by a
RevTag
that is stored under the id to which the tag ref points to.To tell one form the other, you can peel the ref and then test if its
getPeeledObjectId()
returns non-null.The peeled object id is the one that points to the commit on which the annotated tag was created.