Combine merge subtree with sparse validation in git

I am trying to imitate svn: externals in git. In project "A" I need to pull out library "B" in a subfolder of "A". Both A and B are separate git repositories. I know that I can do this using submodules or merging a subtree. However, to complicate matters even more, I need to pull out the subfolder โ€œBโ€ to โ€œAโ€, and not the entire project, because it is a python module that I need to import directly, and I cannot have the root directory structure there or it cannot be imported .

This is pretty easy to do with svn: externals. With git, this 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 ... 
+4
source share
3 answers

B (library) should also be a supermodule that includes the python module submodule

You have chosen a bad tool and leave it at a higher level of abstraction than is required for the task

0
source

Instead of solving this by setting up git, why not just install B anywhere and tell A where to find the submodule to include? If you just add the folder containing the corresponding submodule B to sys.path , you can return home.

0
source

Git is basically all or nothing. It is best to clone the module elsewhere and either symbolize the directory you want or use sys.path .

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

If you are worried about the size of the submodule clone, and you do not need to fix it, you can use --depth=1 when cloning to ignore the history.

Sorry, you cannot clone a subfolder. At best, you can use git-filter-branch to remove everything from the repo except the selected subfolder.

0
source

Source: https://habr.com/ru/post/1401438/


All Articles