user7357954
user7357954

Reputation: 31

How do I download a specific git repository tag?

There's a repository I want to build from, however if I clone the repository, the source I get results in an unstable program. The last version of the source they tagged (1.2) is stable but I'm not sure how to download it using git. From what I've been reading when searching for answers I can clone the repository first then use checkout to switch to the tag;

git clone https://github/project/project.git

cd project

git checkout tags/1.2

This results in detached head mode which I'm not sure is a problem or not. However what I don't get is, when I do checkout it says it switches to the tag in the "working tree". Does that mean now that if I build it with the scripts the dev team included to do so it will build the 1.2 source code only? I did so and I got a program that seemed unstable still. However I can't tell what version it is because it doesn't say (they're fixing that in a later release).

So did I do this correctly? Or am I barking up the wrong tree by using checkout. I mean, ideally I would like to be able to download the source for that tag without having to clone the entire repository but I can't seem to figure out how to do that, if it's even possible.

Upvotes: 2

Views: 2174

Answers (2)

eis
eis

Reputation: 53553

ideally I would like to be able to download the source for that tag without having to clone the entire repository but I can't seem to figure out how to do that, if it's even possible.

You can do like this:

git clone https://github.com/jquery/jquery.git --branch 3.1.1 --depth 1

To fetch a specific tag without other commit history. --branch parameter can take a tag name as well as branch name in modern versions of git, like explained in this answer. --depth 1 results in a shallow clone, doing a checkout without further history. Shallow clone is explained in detail for example here. The example repo I used, jquery, is big enough that you can observe the difference.

This will result in detached state, which is how it's meant to be.

Upvotes: 2

Roland Smith
Roland Smith

Reputation: 43533

As far as I can tell you'r doing it right.

Downloading the repo will include all the tags, unless you have configured git not to download tags.

When you check out a tag (using git checkout 1.2 is sufficient) you do indeed end up in datached head mode. But that should not be a problem. (Run git checkout master to return to HEAD).

After checking out the tag, your working directory should now be at the point that the project was when they tagged the release.

What you might want to do at this point is remove all generated or cached files and build the project from scratch. How to do this depends on the code and the build system. If the project uses make, running make clean usually should do.

Upvotes: 0

Related Questions