在git中将子树合并与稀疏结帐相结合 [英] combine subtree merge with sparse checkout in git

查看:113
本文介绍了在git中将子树合并与稀疏结帐相结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在git中模拟svn:externals。在项目'A'中,我需要将库'B'拉入到'A'的子文件夹中。 A和B都是独立的git回购。我知道我可以用子模块或子树合并来做到这一点。但是,为了进一步复杂化,我需要将'B'的子文件夹拖放到'A'中,而不是整个项目,因为它是一个需要直接导入的python模块,我不能在那里有根目录结构或者它不能被导入。



使用svn:externals很容易。使用git看起来很复杂,甚至是不可能的。



以下是一个例子: 项目B:

  -B 
- src
__init__.py
- 测试
...

项目A:

 < 
- src
A.py(进口B)
- B(部分检查子文件夹'src'作为名称'B')
__init__ .py
- test
...


解决方案
sys.path 。

   -  A 
- src
- B符号链接到../../B/
- B

如果您担心子模块克隆的大小,并且您不需要提交它,那么您可以使用 - depth = 1 当克隆忽略历史。

不幸的是,你无法克隆子文件夹。充其量,你可以使用 git-filter-branch 来删除除了选定的子文件夹之外的任何回购。


I'm trying to emulate svn:externals in git. In project 'A' I need to pull down library 'B' into a sub folder of 'A'. Both A and B are separate git repos. I know I can do this with either submodules or subtree merge. However, to further complicate things, I need to pull down a subfolder of 'B' into 'A', not the whole project because it is a python module that I need to import directly and I can't have the root directory structure there or it can't be imported.

This is pretty easy to do with svn:externals. With git it seems complicated or even impossible.

Here is an example:

Project B:

-B
  - src
    __init__.py
 - test
   ...

Project A:

- A
   - src
     A.py (imports B)
     - B (partial check of sub folder 'src' as name 'B')
        __init__.py
   - test
     ...

解决方案

Git is mostly all-or-nothing. Your best bet is to clone the module elsewhere and either symlink the directory you want, or use sys.path.

- A
   - src
      - B symlink to ../../B/
- B

If you're concerned about size of submodule's clone, and you don't need to commit to it, then you can use --depth=1 when cloning to ignore history.

Unfortunately, you can't clone a subfolder. At best you could use git-filter-branch to delete everything from a repo except a selected subfolder.

这篇关于在git中将子树合并与稀疏结帐相结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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