Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to git clone a specific release?

Tags:

git

github

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 [email protected]:mygitname/theproject.git#1.0.2 for instance?

like image 618
vdegenne Avatar asked Jul 21 '17 15:07

vdegenne


People also ask

Can I clone a specific commit git?

Git Clone From Specific Commit ID There is no direct way to clone directly using the commit ID. But you can clone from a git tag.

How do I clone a specific?

You can clone a specific branch from a Git repository using the git clone –single-branch –branch command. This command retrieves all the files and metadata associated with one branch. To retrieve other branches, you'll need to fetch them later on.

How do I clone only a specific branch?

There are two ways to clone a specific branch. You can either: Clone the repository, fetch all branches, and checkout to a specific branch immediately. Clone the repository and fetch only a single branch.


2 Answers

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

$ git clone  [email protected]:mygitname/theproject.git --branch 1.0.2 

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

like image 124
jordanm Avatar answered Sep 30 '22 11:09

jordanm


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).

like image 39
Mark Adelsberger Avatar answered Sep 30 '22 11:09

Mark Adelsberger