如何克隆特定版本的 git 存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10303665/
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 clone a specific version of a git repository?
提问by Sen?i
I'm working with symfony2 and I want to backup my vendors in case github is not reachable.
我正在使用 symfony2,我想备份我的供应商,以防 github 无法访问。
How do I clone a specific Version of a repository?
如何克隆存储库的特定版本?
I want to backup the repositories with help of the vendors-file.
我想在供应商文件的帮助下备份存储库。
the syntax is something like this:
语法是这样的:
[symfony]
git=http://github.com/symfony/symfony.git
version=v2.0.9
now how do I tell git to get that specific version? Is there a terminal-command like:
现在我如何告诉 git 获取该特定版本?是否有终端命令,如:
git clone --mirror http://github.com/symfony/symfony.git --version=v2.0.9
Thanks in Advance
提前致谢
回答by Matt
What I would do to tell git to use this exact version is:
我会告诉 git 使用这个确切的版本是:
git clone http://github.com/symfony/symfony.git
cd symfony
git checkout v2.0.9
One liner:
一个班轮:
git clone http://github.com/symfony/symfony.git -b v2.0.9
回答by GoZoner
The following might get you there:
以下可能会让你到达那里:
git clone --branch <branch> <repo>
If you are looking for a specific version, then first create a branch off that version from your working repository. Like such:
如果您正在寻找特定版本,请首先从您的工作存储库中创建该版本的分支。像这样:
# In a local, working repository
git checkout -b v2.0.9-br v2.0.9
git push origin
# Now create your clone from v2.0.9-br
Note, I've assumed v2.0.9 is a version (tag), not a branch. If it is a branch, then just clone with the '--branch' option.
注意,我假设 v2.0.9 是一个版本(标签),而不是一个分支。如果它是一个分支,那么只需使用 '--branch' 选项进行克隆。
回答by Vincent B.
You can't clone a repository specifying only a version number. You also can't clone a repository by specifying only a commit hash. (which is pretty much the same thing from Git's point of view)
您不能克隆仅指定版本号的存储库。您也不能通过仅指定提交哈希来克隆存储库。(从 Git 的角度来看,这几乎是一样的)
Actually the only thing you can do is a shallow clone by specifying the depth (the number of commits you will pull): http://linux.die.net/man/1/git-clone
实际上,您唯一可以做的就是通过指定深度(您将拉取的提交数量)进行浅层克隆:http: //linux.die.net/man/1/git-clone
git clone --depth 1
would pull only the last commit.
git clone --depth 1
只会拉最后一次提交。
Back to your question, if you fear that github is unreachable, you should host these projects on one of your server.
回到你的问题,如果你担心 github 无法访问,你应该在你的一台服务器上托管这些项目。