tags:

views:

13111

answers:

5

I'm trying to figure out how do download a particular tag of a git repository - it's one version behind the current version.

I saw there was a tag for the previous version on the git web page, with object name of something long hex number.

But the version name is "Tagged release 1.1.5" according the site.

I tried a command like this (with names changed):

git clone http://git.abc.net/git/abc.git my_abc

And I did get something - a directory, a bunch of subdirectories, etc.

If it's the whole repository, how do I get at the version I'm seeking? If not, how do I download that particular version?

+35  A: 

git clone will give you the whole repository.

After the clone, you can list the tags with git tag -l and then checkout a specific tag: git checkout <tag_name>

Renato Besen
Yep. git is different to subversion in this respect. A svn tag basically copies the files to a new folder, so you can svn checkout a specific bunch of files, whereas git tags are simply pointers to specific revisions.
dbr
@Renato, after git checkout <tag_name>, can work on the same and commit to it, just treating <tag_name> as a <branch_name> ?? I thought <tag_name> is given for a special commit(as a release), but treating that as a branch is confusing and opposite right?
Maddy
Found the answer here:http://blog.stonean.com/2009/02/17/git-branch-from-a-tag/
Maddy
+9  A: 

I'm not a git expert, but I think this should work:

git clone http://git.abc.net/git/abc.git
git checkout my_abc OR git checkout -b new_branch my_abc

The second variation on the second line establishes a new branch based on the tag, which lets you avoid a 'detached HEAD'. (git-checkout manual)

Every git repo contains the entire revision history, so cloning the repo gives you access to the latest commit, plus everything that came before, including the tag you're looking for.

grossvogel
+2  A: 

You can use git archive to download a tar ball for a given tag or commit id:

git archive --format=tar --remote=[hostname]:[path to repo] [tag name] > tagged_version.tar
Chris J
This command does not work with submodules, see http://stackoverflow.com/questions/1591387/need-to-handle-git-submodules-in-git-archive
Zitrax
A: 

I checked the git checkout documentation, it revealed one interesting thing:

git checkout -b <new_branch_name> <start_point> , where the <start_point> is the name of a commit at which to start the new branch; Defaults to HEAD

So we can mention the tag name( as tag is nothing but a name of a commit) as, say:

>> git checkout -b 1.0.2_branch 1.0.2
later, modify some files
>> git push --tags

P.S: In Git, you can't update a tag directly(since tag is just a label to a commit), you need to checkout the same tag as a branch and then commit to it and then create a separate tag.

Maddy
+1  A: 

If your tags are sortable using the linux 'sort' command, use this:

git tag | sort -n | tail -1

eg. if git tag returns:

v1.0.1
v1.0.2
v1.0.5
v1.0.4

git tag | sort -n | tail -1 will output:

v1.0.5

git tag | sort -n | tail -2 | head -1 will output:

v1.0.4

(because you asked for the second most recent tag)

to checkout the tag, first clone the repo, then type:

git checkout v1.0.4

..or whatever tag you need.

Peter Johnson