如何 git clone 特定版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45241502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:03:47  来源:igfitidea点击:

how to git clone a specific release?

gitgithub

提问by vdegenne

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 pusheverything remotely.

push一切远程。

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 commitand create a new tag(v2.0.0), to git clone a specific state of the git providing a tag ?

稍后,当我进行这些改进并commit创建一个新的tagv2.0.0)时,是否有可能git clone 提供标签的 git 的特定状态?

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

如果最后一个版本是v2.0.0,我还可以克隆1.0.x版本吗?

something like git clone [email protected]:mygitname/theproject.git#1.0.2for instance ?

诸如此类的东西git clone [email protected]:mygitname/theproject.git#1.0.2

回答by jordanm

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

您可以使用--branch标志执行此操作,该标志也将接受标签。

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

在大多数情况下,您只想按照 Exprator 的回答中所述签出标签。

回答by Mark Adelsberger

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

使用 git,您通常不会克隆特定版本;你clone整个回购 - 制作每个版本的本地副本 - 然后checkout是特定版本。

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

默认情况下,当您克隆时,会签出特定版本(通常为master)。您可以使用该-b选项更改检出的版本(当然,您也可以在克隆完成后检出所需的版本)。

But there are scenarios where that's not practically useful advice, such as if you're using npmto fetch something from git (so you don't directly issue a clonecommand). 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 onlyworks with npmthough; it doesn't work with git clonethe way you asked about.)

但是在某些情况下,这并不是实际有用的建议,例如,如果您使用npm从 git 获取某些内容(因此您不直接发出clone命令)。对于npm,您可以将提交标识符(分支、标签、提交 SHA 等)作为哈希片段添加到 URL 的末尾。(AFAIK适用于npm;它不适用于git clone您询问的方式。)

For completeness's sake, if you reallywanted 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

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

(其中branch_name是分支或标签的名称)。