3

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.

Nana89
  • 432
  • 4
  • 21
  • You can use the `CheckoutCommand` to checkout the revision to which the tag points into the work dir. If you are looking for something else, please clarify what 'load' and 'temporary access' means exactly. – Rüdiger Herrmann Nov 17 '15 at 17:44
  • By 'load' I mean, having a copy of the tag content. Each tag in my git project is a different version of the software. – Nana89 Nov 17 '15 at 18:26

1 Answers1

8

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.

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