使用 Git 和 Mercurial 进行部分克隆 [英] Partial clone with Git and Mercurial

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

问题描述

是否可以在 Git 和 Mercurial 中只克隆一个分支(或从给定的提交)?我的意思是,我想克隆一个中央存储库,但由于它很大,我只想获取其中的一部分,并且仍然能够回馈我的更改.是否可以?比如,我只想要标签 130 或类似的东西?

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?

如果是,怎么做?

推荐答案

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

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

  • 浅层克隆:我想要从修订点 X 开始的历史记录.

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

使用 git clone --depth <n><url>,但请记住,浅克隆在与其他存储库的交互方面有些受限.您将能够生成补丁并通过电子邮件发送它们.

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.

按文件路径进行部分克隆:我想要某个目录 /path 中的所有修订历史记录.

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

在 Git 中不可能.使用现代 Git,尽管您可以稀疏检出,即您拥有完整的历史记录,但您仅检出(在工作区中)所有文件的子集.

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).

可能,和

在 git 1.7.10 之前并不简单:您需要手动执行 clone 操作,即 git init [],然后 git remote add origin ,编辑.git/config 用请求的分支(可能是'master')替换remote.origin.fetch 中的*,然后git fetch .

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 .

自 git 1.7.10 起git clone 提供了 --single-branch 选项似乎就是为了这个目的而添加的,而且看起来很简单.

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.

如果您知道人们希望如何通过文件路径(同一存储库中的多个项目)分解事物,您可以使用子模块(有点像 svn:externals)将存储库预先拆分为可单独克隆的部分.

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天全站免登陆