如何 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
how to git clone a specific release?
提问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 push
everything 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 commit
and create a new tag
(v2.0.0), to git clone a specific state of the git providing a tag ?
稍后,当我进行这些改进并commit
创建一个新的tag
(v2.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.2
for instance ?
诸如此类的东西git clone [email protected]:mygitname/theproject.git#1.0.2
?
回答by jordanm
You can do this with the --branch
flag, 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 clone
the entire repo - making a local copy of the every version - and then checkout
a 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 -b
option (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 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 onlyworks with npm
though; it doesn't work with git clone
the 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_name
is the name of either a branch or a tag).
(其中branch_name
是分支或标签的名称)。