只克隆一个分支[重复]

本文翻译自:Clone only one branch [duplicate]

This question already has an answer here: 这个问题在这里已有答案:

I would like to know how I could clone only one branch instead of cloning the whole Git repository. 我想知道如何克隆一个分支而不是克隆整个Git存储库。


#1楼

参考:https://stackoom.com/question/KBfm/只克隆一个分支-重复


#2楼

From the announcement Git 1.7.10 (April 2012): 从公告Git 1。7。10 (2012年4月):

  • git clone learned --single-branch option to limit cloning to a single branch (surprise!); git clone --single-branch选项将克隆限制为单个分支(惊喜!); tags that do not point into the history of the branch are not fetched. 不提取未指向分支历史记录的标记。

Git actually allows you to clone only one branch, for example: Git实际上允许您只克隆一个分支,例如:

git clone -b mybranch --single-branch git://sub.domain.com/repo.git

Note : Also you can add another single branch or "undo" this action. 注意您还可以添加另一个分支或“撤消”此操作。


#3楼

--single-branch ” switch is your answer, but it only works if you have git version 1.8.X onwards, first check --single-branch ”开关是你的答案,但它只适用于git版本1.8.X以后,首先检查

#git --version 

If you already have git version 1.8.X installed then simply use "-b branch and --single branch" to clone a single branch 如果你已经安装了git版本1.8.X,那么只需使用“-b branch和--single branch”来克隆一个分支

#git clone -b branch --single-branch git://github/repository.git

By default in Ubuntu 12.04/12.10/13.10 and Debian 7 the default git installation is for version 1.7.x only, where --single-branch is an unknown switch. 默认情况下,在Ubuntu 12.04 / 12.10 / 13.10和Debian 7中,默认的git安装仅适用于1.7.x版本,其中--single-branch是一个未知的交换机。 In that case you need to install newer git first from a non-default ppa as below. 在这种情况下,您需要首先从非默认的ppa安装更新的git,如下所示。

sudo add-apt-repository ppa:pdoes/ppa
sudo apt-get update
sudo apt-get install git
git --version

Once 1.8.X is installed now simply do: 安装1.8.X后,现在只需:

git clone -b branch --single-branch git://github/repository.git

Git will now only download a single branch from the server. Git现在只从服务器下载一个分支。


#4楼

我用下面的单个git命令完成了:

git clone [url] -b [branch-name] --single-branch

#5楼

You could create a new repo with 您可以创建一个新的仓库

git init 

and then use 然后使用

git fetch url-to-repo branchname:refs/remotes/origin/branchname

to fetch just that one branch into a local remote-tracking branch. 仅将该分支提取到本地远程跟踪分支。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值