使用Git克隆时只选择文件夹的子集 [英] Pick only subset of folders when using Git clone

查看:79
本文介绍了使用Git克隆时只选择文件夹的子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述









$有以下文件夹结构:

A


| _ B


| _ C


| _ D



克隆后,我想要:

A


| _ C


| _ D



我想用这个用于部署我的应用程序的流程:


  • 通过仅取回部分回购并忽略不必要的开发文件来提高克隆速度。

  • 由于安全原因,我不希望生产一些文件。



有什么建议吗?如注释所示,你不能克隆路径的一部分。如果你习惯于不同的源代码控制模式,例如颠覆使用的模式,那么起初这可能看起来不直观。你无法做到的原因是因为git存储了整个树的快照。所以你可以得到一个浅层克隆,这意味着你只能获得最近的历史。这更像是一个水平分割或截断,而不是你之后的垂直分割。



获得所需内容的最佳方法是使用子模块。如果您已经拥有一个存储库中的所有内容,则必须从此模式开始,或者使用filter-branch将存储库拆分为多个存储库。这也将是棘手的,因为你最终会在所有仓库提交空提交,如果摆脱这些,你会有一些棘手的后续过滤器分支,以将子模块中的正确提交与父仓库绑定。



请查看有关子模块 at http://git-scm.com/book


Is there a way to clone only subset of the original branch in git?

E.g.

I have following folders structure:

A
|_ B
|_ C
|_ D

And after clone I want to have:

A
|_ C
|_ D

I want to use this flow for deploying my application:

  • To make clone faster by taking only part of the repo and ignoring unnecessary development files.
  • I don't want to have some files in production because of security reasons.

Any advice?

解决方案

As the comment suggests, you can't clone part of a path. If you are used to different source control paradigms such as the one used by subversion, this may seem unintuitive at first. The reason you can't do it is because git stores snapshots of the whole tree. So you can get a shallow clone, meaning you get only recent history up to a point. This is more like a horizontal slice or cut-off, rather than the vertical one you are after.

The best way to get what you want is to use submodules. If you already have everything in one repository, you would have to either start fresh with this paradigm or tease apart the repository into multiple repositories with filter-branch. This would also be tricky as you would end up with empty commits in all repos and if get rid of those, you would have some tricky follow up filter branching to tie the proper commits in the submodule to the parent repository.

Take a look at the chapter on submodules at http://git-scm.com/book.

这篇关于使用Git克隆时只选择文件夹的子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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