简体   繁体   中英

Git Submodule - add files from a repository to a folder as submodule

I confused the concept of Git submodules.

I created separate repositories intended to be submodules of another project, then in the main project repository I added empty folders to where these files should be added.

example:

MyProject/
   ./lib
   ./headers
   ./source

those folders are empty because the contents will be coming from the separate repos as submodules but the thing is that they are named differently. the contents of lib/ will be coming from lib_trunk submodule and source is called source_trunk

is there a way to tweak the submodules feature in git to instead clone the repo as named it will just add the files contained in the repository?

You don't need to create the folders in advance, git will do it for you. And those folders can be named differently than the -submodule- repositories they contain.

git submodule add url/to/lib_trunk lib

will initialize a submodule in a lib folder from a repository called lib_trunk . Same thing with source .

If, as you say, both lib and source already exist, you may have to delete them before doing git submodule add (but as they're empty there is no reason to keep them).

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