开发者

Git Submodules. How do I make them entirely self-contained?

开发者 https://www.devze.com 2022-12-08 10:07 出处:网络
I\'m a happy user of Github. Over time I have accrued a number of little unrelated toy repos. I would now like to create a container r开发者_如何学Pythonepo - call it playpen, pull my various toy proj

I'm a happy user of Github. Over time I have accrued a number of little unrelated toy repos. I would now like to create a container r开发者_如何学Pythonepo - call it playpen, pull my various toy projects underneath the parent playpen as git submodules, and blow away to source toy repos. The toys should only live in the playpen. When I tried this using this recipe: http://git.or.cz/gitwiki/GitSubmoduleTutorial I discovered a big problem. See, I want to completely the repos and have them only live beneath playpen. When I went ahead and blew away the repos in github I was not able to follow the links within the playpen. Huh?

Could someone please explain to me how to do this? Thanks in advance

Cheer, Doug


A submodule is a way of linking repositories together, but each submodule is it's own complete self-contained repository. When you add a repository as a submodule of another repository you are only linking the repositories together, you are not moving the data into the parent repository. For this reason you can't delete the repository that is the submodule without breaking this link.


You can combine your various repositories into a single repository, but not with submodules. Although the method I can suggest dose have a serious downside. After merging your toy projects they no longer act as separate projects. You can't make a commit to just one project, you have to commit to all of them at the same time. Similarly you can't branch just one of the projects, each branch is a branch of all the projects. So, if you have used multiple branches or there is any chance that you will want to branch an individual project in the future then stick with separate repositories.

If after all that you still want to merge your various repositories then you can use part of the idea from how to use the subtree merge strategy. Although since you're not planning on keeping around the old repositories you will never need to use the subtree merge.

The important bit from the subtree merge strategy document are the following commands, which you should run from the new container repository:

$ git remote add -f Bproject /path/to/B
$ git merge -s ours --no-commit Bproject/master
$ git read-tree --prefix=dir-B/ -u Bproject/master
$ git commit -m "Merge B project as our subdirectory"

Since you're going to delete the original repository you can also delete the remote you added at the beginning so it doesn't clutter things up.

$ git remote rm Bproject

At this point your container repository contains the Bproject. You can repeat these steps to merge in additional projects. However, as I alluded to before, only the master branch has been merged, any other branches your projects may have had won't be merged.

0

精彩评论

暂无评论...
验证码 换一张
取 消