Download a specific tag with Git

2019-01-01 02:56发布

I'm trying to figure out how I can 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?

15条回答
回忆,回不去的记忆
2楼-- · 2019-01-01 03:14

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.

查看更多
泛滥B
3楼-- · 2019-01-01 03:16

Use the --single-branch switch (available as of Git 1.7.10). The syntax is:

git clone -b <tag_name> --single-branch <repo_url> [<dest_dir>] 

For example:

git clone -b 'v1.9.5' --single-branch https://github.com/git/git.git git-1.9.5

The benefit: Git will receive objects and (need to) resolve deltas for the specified branch/tag only - while checking out the exact same amount of files! Depending on the source repository, this will save you a lot of disk space. (Plus, it'll be much quicker.)

查看更多
永恒的永恒
4楼-- · 2019-01-01 03:16

try:

git clone -b <name_of_the_tag> <repository_url> <destination>
查看更多
长期被迫恋爱
5楼-- · 2019-01-01 03:19
$ 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 tags/<tag_name>

Even better, checkout and create a branch (otherwise you will be on a branch named after the revision number of tag):

$ git checkout tags/<tag_name> -b <branch_name>
查看更多
无与为乐者.
6楼-- · 2019-01-01 03:23

first fetch all the tags in that specific remote

git fetch <remote> 'refs/tags/*:refs/tags/*'

or just simply type

git fetch <remote>

Then check for the available tags

git tag -l

then switch to that specific tag using below command

git checkout tags/<tag_name>

Hope this will helps you!

查看更多
闭嘴吧你
7楼-- · 2019-01-01 03:24

Clone with -b option also helps: git clone https://git01.codeplex.com/aspnetwebstack.git -b v2.0

The following post uses the above option to download asp.net mvc: http://vijayt.com/Post/Setting-up-aspnet-mvc-for-debugging-in-your-system

查看更多
登录 后发表回答