Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are right, Git submodules can not directly do exactly what you want. It works in SVN because the root of a repository, branches, and any subdirectory thereof are the same kind of object. In Git, a repository, a branch, and a directory are all distinct kinds of objects (you can not use a directory as a full repository or as a branch).</p> <p>There are a couple of indirect ways to accomplish what you want though.</p> <h2>Using Submodules and Symlinks</h2> <p>The core of a Git submodule is a clone of another repository in the work tree of the “superproject”<sup>*</sup>. Git only clones full repositories. It is not possible to clone just a single subdirectory out of an existing repository<sup>†</sup>.</p> <p><sup>*</sup> Normal submodules also require a special reference in the superproject's commits/index and (normally) an entry in the superproject's <code>.gitmodules</code> file. It is possible to have non-tracked clones of other repositories in an unrelated working tree, but such usage does not create a submodule.<br> <sup>†</sup> Git 1.7.0 and later has a “sparse checkout” feature, but it would not help to relocate the <code>lib</code> directory the top level of each submodule clone.</p> <p>You might, however be able to use Git's support for symbolic links to do something that is fairly close:</p> <pre><code># # Make the lib directory of each submodule appear in the superproject as # lib/vendor/packages/$submod_name # # With this structure in each of the submodules (a, b, c): # # lib/ # tests/ # # We end up with this structure in the superproject: # # lib/ # vendor/ # packages/ # a (a symlink to ../../../_submodules/a/lib) # b (a symlink to ../../../_submodules/b/lib) # c (a symlink to ../../../_submodules/c/lib) # _submodules # a/ (a Git submodule) # lib/ # tests/ # b/ (a Git submodule) # lib/ # tests/ # c/ (a Git submodule) # lib/ # tests/ # add_one() { dir=lib/vendor/package dest="$dir/$1" # use fewer ".."s to put the _submodules closer to the symlinks s=../../../_submodules/"$1" git submodule add "$2" "$dir/$s" ln -s "$s"/lib "$dest" git add "$dest" } cd "$main_repo_toplevel" mkdir -p lib/vendor/package add_one a git@githost.example.com:user/package-a.git add_one b git://public.example.com/work/package-b-dev.git add_one c ssh://special.example.com/foo.git </code></pre> <h2>Using <em>git subtree</em></h2> <p>apenwarr's <a href="http://github.com/apenwarr/git-subtree" rel="nofollow noreferrer"><em>git subtree</em></a> can split off and merge parts of repositories (i.e. individual subdirectories; it is a wrapper around <a href="http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html" rel="nofollow noreferrer">“subtree merging”</a> with other nice features). The first step would be to extract the history of <code>lib</code> in each of your sub-projects. Then, either directly use the extracted history as a submodule, or use <em>git subtree</em> to do a subtree merge into your main repository. Either way, this would introduce an extra step (re-extracting the <code>lib</code> history) before you could integrate changes from a sub-project into your main repository.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload