Is there a way to add a submodule to a git repo that share a directory structure

StackOverflow https://stackoverflow.com/questions/23569821

  •  19-07-2023
  •  | 
  •  

Question

I have a repo with a directory structure like so /foo /foo/bar /foo/bar/me /foo/bar/you /foo/one /foo/one/two /foo/one/three

There is a submodule I want to add that has this structure /foo/bar/file.txt /foo/one/otherfile.txt

Is there way to add that submodule to my repo, where the submodule shares some of the same directory structure? I've tried using the basic add submodule commands, but I get the error that 'foo' already exists in the index, which I take to mean that becuase my repo already has a /foo directory, it can't add the submodule with the same directory.

Is there anyway to have the submodule share the directory structure, but still have different files?

Était-ce utile?

La solution

Check out the submodule into a subfolder, for example /foo/submodule, so it looks like this:

/foo/submodule/foo/bar/file.text
/foo/submodule/foo/one/otherfile.txt

Then simply link the files in your repo:

/foo/bar/file.txt --> link to ../submodule/foo/bar/file.txt
/foo/one/otherfile.txt --> link to ../submodule/foo/one/otherfile.txt

This could even be expanded to automatically update the links and remove dead links when you update the submodule by a git hook if necessary.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top