如何在git中克隆单个分支? [英] How to shallow clone a single branch in git?

查看:800
本文介绍了如何在git中克隆单个分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git repo我想做一个浅拷贝,并且只拉一个分支。



这个问题说git clone默认会拉动所有远程分支。我想只做一个分支的浅表副本。



我正在执行此操作以部署到生产环境中。全额结账超过400MB,但是头部的git存档只有16MB。看起来克隆的拉下所有分支的行为导致我的下载比必要的大得多。

解决方案

Jakub

a>已经提到选定分支的浅层克隆是可能的,但相当复杂做$。
然后他补充说:


请注意,因为分支通常分享他们大部分的历史,从克隆只有一部分分支可能比你想象的小。


我会补充说,你不应该有任何VCS工具一个生产平台(您只安装/监控生产所需的 run )。

So git archive 仍然是提取您的最佳方式需要作为档案( zip tar )格式,然后您可以使用没有Git,一旦转移到生产端)






2012年3月更新:

即将推出的git1.7.10 (2012年4月)将实际上允许你克隆只有一个分支:

  git clone --single-branch 

你可以在
<$> p $ p> test_expect_success'single branch clone''
git clone --single-branchfile:// $(pwd)/。 singlebranch
'

然后修复这个功能:





clone --single :将fetch refspec限制为获取分支




运行 git clone --single ,则生成的存储库具有通常默认的 + refs / heads / *:refs / remotes / origin / * 安装了通配符提取refspec, git fetch 将最终抓住所有其他分支。



更新fetch refspec仅覆盖单个克隆的参考反而改正这一点。






builtin / clone.c:检测从标签开始的克隆正确




31b808a clone --single :限制获取refspec获取分支,2012-09-20)尝试查看给定的分支是否遵循实际上是通过检查 refs / tags / 在远程存储库中的标签,但它错误地使用了 strstr(3);对分支 refs / heads / refs / tags / foo 进行处理并使用 refs / tags的逻辑是错误的/
ref层次结构。

代码真正想要做的是看它是否以 refs / tags /







2016年9月更新:git clone --single-branch --branch tag 将在Git中用于链式标签 2.11+(2016年第四季度)。

I have a git repo I'd like to do a shallow copy on, and only pull a single branch.

This SO question says that git clone by default pulls all remote branches. I'd like to do a shallow copy of only a single branch.

I'm doing this to deploy into production. A full checkout is over 400MB, but a git archive of head is only 16MB. It appears that clone's behavior of pulling down all the branches causes my download to be much larger than necessary.

解决方案

Jakub already mentioned a shallow clone of selected branches is possible, but quite complex to do.
And he added:

Note however that because branches usually share most of their history, the gain from cloning only a subset of branches might be smaller than you think.

I would add that you shouldn't have any VCS tool in a production plateform (you only install/monitor what is necessary for the production to run).
So git archive remains the best way to extract just what you need, as an archive (zip or tar, format that you can then uses without Git, once transferred on the production side)


Update March 2012:

the upcoming git1.7.10 (April 2012) will actually allow you to clone only one branch:

git clone --single-branch

You can see it in t5500-fetch-pack.sh:

test_expect_success 'single branch clone' '
  git clone --single-branch "file://$(pwd)/." singlebranch
'

That feature was then fixes with:

clone --single: limit the fetch refspec to fetched branch

After running "git clone --single", the resulting repository has the usual default "+refs/heads/*:refs/remotes/origin/*" wildcard fetch refspec installed, which means that a subsequent "git fetch" will end up grabbing all the other branches.

Update the fetch refspec to cover only the singly cloned ref instead to correct this.

builtin/clone.c: detect a clone starting at a tag correctly

31b808a (clone --single: limit the fetch refspec to fetched branch, 2012-09-20) tried to see if the given "branch" to follow is actually a tag at the remote repository by checking with "refs/tags/" but it incorrectly used strstr(3); it is actively wrong to treat a "branch" "refs/heads/refs/tags/foo" and use the logic for the "refs/tags/" ref hierarchy.
What the code really wanted to do is to see if it starts with "refs/tags/".


Update Sept 2016: git clone --single-branch --branch tag will work for chained tags in Git 2.11+ (Q4 2016).

这篇关于如何在git中克隆单个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆