git clone 和 checkout 在一个命令中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18525152/
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
git clone and checkout in a single command
提问by user2731584
The following is the command I use to checkout a specific commit.
以下是我用来检出特定提交的命令。
git clone git://repo.git/repo123
git checkout <commitID>
I want to do the above in one step - using a git clone command only.
我想一步完成上述操作 - 仅使用 git clone 命令。
The reason why I want to do this is, repo123 is very huge. So checking out the commit I want will save me a lot of time.
我想这样做的原因是,repo123 非常庞大。因此,检查我想要的提交将为我节省很多时间。
I am aware of --depth
option. But in this case, it is of no use. Can anyone tell me how to do it?
我知道--depth
选项。但在这种情况下,它是没有用的。谁能告诉我怎么做?
回答by jthill
git clone u://r/l --branch x
still clones everything but sets the local HEAD to that branch so it's the one checked out.
仍然克隆所有内容,但将本地 HEAD 设置为该分支,因此它是签出的那个。
来源:
--branch <name>
-b <name>
Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository's HEAD, point to<name>
branch instead. In a non-bare repository, this is the branch that will be checked out.--branch
can also take tags and detaches the HEAD at that commit in the resulting repository.
--branch <name>
-b <name>
不是将新创建的 HEAD 指向克隆存储库的 HEAD 指向的<name>
分支,而是指向分支。在非裸存储库中,这是将被检出的分支。--branch
还可以在生成的存储库中的该提交处获取标签并分离 HEAD。
回答by michas
Is your problem the checkoutbeing to large or the repositoryitself?
As git clone
, well, clones a repository you usually get the whole repository in its full size. (unless you are doing a shallow clone as you already suggested.)
您的问题是结帐过大还是存储库本身?作为git clone
,那么,克隆一个仓库,你通常得到的全尺寸全库。(除非您按照您的建议进行浅层克隆。)
If it's really about the checkout of the wrong branch git help clone
says:
如果真的是关于错误分支的结帐,请git help clone
说:
--no-checkout, -n
No checkout of HEAD is performed after the clone is complete.
After cloning with -n
you can manually check out
克隆后-n
你可以手动签出
回答by Mir S Mehdi
I was running into a same situation and it worked well with the Git Clone Command with --depth
. And specify the branch-name/commit/Tag-Name at the end of the command with -b
parameter.
我遇到了同样的情况,它与带有--depth
. 并在命令末尾带-b
参数指定branch-name/commit/Tag-Name 。
Syntax:
句法:
git clone --depth 1 github.com:ORG-NAME/Repo.git -b <Branch-Name/Commit-Number/TAG>