部分克隆与Git和Mercurial [英] Partial clone with Git and Mercurial

查看:195
本文介绍了部分克隆与Git和Mercurial的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Git和Mercurial中克隆只有一个分支(或来自给定的提交)?我的意思是,我想克隆一个中央回购,但因为它很大,我只想得到它的一部分,仍然能够回馈我的变化。可能吗?喜欢,我只想从Tag 130开始或类似的东西?



如果是这样,怎么样?

解决方案

在Git领域,您正在谈论三种不同类型的部分克隆:


  • 浅层克隆: clone --depth< n> < url> ,但请记住浅层克隆在与其他存储库交互时有一定的局限性。您可以生成补丁并通过电子邮件发送。

  • 我希望所有修订历史记录都位于某个目录 / path 中。



    不可用 in Git的。使用现代Git,尽管您可以拥有稀疏结帐,即您拥有完整的历史记录,但您只能查看(在工作区域中)只有所有文件的子集。

    我只想克隆一个分支(或分支的选定子集)。



    可能的,

    在git 1.7.10之前并不简单:您需要手动执行clone, code> git init [< directory>] ,然后 git remote add origin< url> ,编辑 .git / config remote.origin.fetch 中替换 * 可能是'master'),然后 git fetch



    git clone 提供 - 单一分支 选项,它似乎是为此目的而添加的,看起来很简单。



    请注意,因为分支通常分享大多数的历史,从克隆分支的一个子集的收益可能会比你想象的小。 如果你知道人们希望通过filepath(同一个存储库中的多个项目)来分解东西,你可以使用子模块(有点像svn:externals)来预先将repo分成独立的可复制部分。


    Is it possible to clone only one branch (or from a given commit) in Git and Mercurial? I mean, I want to clone a central repo but since it's huge I'd like to only get part of it and still be able to contribute back my changes. Is it possible? Like, I only want from Tag 130 onwards or something like that?

    If so, how?

    解决方案

    In Git land you are talking about three different types of partial clones:

    • shallow clones: I want history from revision point X onward.

      Use git clone --depth <n> <url> for that, but please remember that shallow clones are somewhat limited in interacting with other repositories. You would be able to generate patches and send them via email.

    • partial clone by filepath: I want all revision history history in some directory /path.

      Not possible in Git. With modern Git though you can have sparse checkout, i.e. you have whole history but you check out (have in working area) only subset of all files.

    • cloning only selected branch: I want to clone only one branch (or selected subset of branches).

      Possible, and

      before git 1.7.10 not simple: you would need to do what clone does manually, i.e. git init [<directory>], then git remote add origin <url>, edit .git/config replacing * in remote.origin.fetch by requested branch (probably 'master'), then git fetch .

      as of git 1.7.10 git clone offers the --single-branch option which seems like it was added just for this purpose, and seems pretty easy.

      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.

    You can also do a shallow clone of only selected subset of branches.

    If you know how people will want to break things down by filepath (multiple projects in the same repository) you can use submodules (sort of like svn:externals) to pre-split the repo into separately cloneable portions.

    这篇关于部分克隆与Git和Mercurial的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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