Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load content from Tag with JGit

Tags:

java

git

jgit

In Java I'm trying to load the content pointed by a tag of my git repository. I would like to have temporary access to the version subfolders that correspond to that tag. I've tried to use the parseTag method of RevWalk, but I'm not sure if this is the right way as I found in the documentation that ObjectLoader can be the highway to solve this. Still not sure which one should I use.

like image 976
Nana89 Avatar asked Nov 26 '25 21:11

Nana89


1 Answers

You can use the CheckoutCommand to checkout a tag into the working directory.

For example:

git.checkout().setName("refs/tags/my-tag").call();

will checkout the tag my-tag into the work dir.

Note, however, that the operation leads to a detached HEAD. If that's not desied, you need to advice the CheckoutCommand to create a branch for you.

For example

git.checkout()
    .setCreateBranch(true)
    .setName("my-branch")
    .setStartPoint("refs/tags/my-tag")
    .call();

will create and checkout a branch named my-branch that points to the commit referred to by my-tag.

like image 67
Rüdiger Herrmann Avatar answered Nov 29 '25 10:11

Rüdiger Herrmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!