简体   繁体   中英

How to git clone a specific release?

So that's it, I finished the very first version of my application.

I committed the final state of the first version:

git commit -m "some final tweaks"

and created the versioning tag:

git tag v1.0.0

and push everything remotely.

Now, I am in the process of starting developing the second version of the application with some improvements I already have in mind.

Is it possible, later, when I'd made these improvements and commit and create a new tag ( v2.0.0 ), to git clone a specific state of the git providing a tag?

If the last version is v2.0.0 , can I still clone the version 1.0.x ?

Something like git clone git@github.com:mygitname/theproject.git#1.0.2 for instance?

You can do this with the --branch flag, which will also accept a tag.

$ git clone  git@github.com:mygitname/theproject.git --branch 1.0.2

In most cases, you will just want to checkout the tag as described in Exprator's answer.

With git you usually don't clone a particular version; you clone the entire repo - making a local copy of the every version - and then checkout a specific version.

By default when you clone, a specific version (usually master ) is checked out. You can change which version is checked out with the -b option (or, of course, you can just check out the desired version after the clone completes).

But there are scenarios where that's not practically useful advice, such as if you're using npm to fetch something from git (so you don't directly issue a clone command). In the case of npm , you can add a commit identifier (branch, tag, commit SHA, etc.) to the end of the URL as a hash fragment. (AFAIK that only works with npm though; it doesn't work with git clone the way you asked about.)

For completeness's sake, if you really wanted to clone just a particular version (copying only that version from the remote to your local machine), you could do something like

git clone --depth 1 -b branch_name <url>

(where branch_name is the name of either a branch or a tag).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM