简体   繁体   English

Git拉/克隆分支

[英]Git pull/clone a branch

I need to fetch the files from just one specific branch. 我只需要从一个特定的分支中获取文件。 I have tried a couple of commands, but it ends up pulling the whole repo, instead of just the few files I need to pull to a directory from the specific branch. 我已经尝试了几个命令,但是最终导致拉回整个存储库,而不仅仅是拉出一些需要从特定分支拉到目录的文件。

git version 1.7.1 git版本1.7.1

If you get an error on: 如果出现以下错误:

git clone git@bitbucket.org:name/name.git -b mv_LookbookAddition --single-branch

It means you need to 1.7.10+ (June 2012), using, for Linux, a ppa or git-scm.com/download/mac for Mac. 这意味着您需要1.7.10+(2012年6月),对于Linux使用ppagit-scm.com/download/mac(对于Mac)。

But you will get the full history of the branch (if that branch has been created from master , you will get all the commits from master , up until the branch starts, plus the branch commits) 但是你会得到分支的完整历史记录(如果分支已经从创造master ,你会得到所有提交的master ,直到分支开始,加上分支提交)

You can try and combine the --depth option to get only the last commits from the branch alone 您可以尝试结合--depth选项仅从分支中仅获取最后的提交

git clone git@bitbucket.org:name/name.git -b yourBranch --single-branch --depth 10

That will your cloned repo a shallow repo, which is why you want a git 2.0+ (because you can create commits and push back, from your shallow repo) . 这将使您的克隆存储库成为浅存储库,这就是为什么您想要git 2.0+的原因(因为您可以从浅存储库创建提交并回退)

See explainshell.com . 请参阅explainshell.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM