简体   繁体   中英

combine subtree merge with sparse checkout in git

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

B (library) must be also supermodule, which include submodule "python module"

You selected bad tool and leave on higher abstraction layer, than needed for task

Instead of solving it by tweaking git, why not just install B anywhere, and tell A where to find the submodule to include? If you just add to sys.path the folder containing the relevant B submodule, you can go home.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM