Create a git repository that contains another git repository

情到浓时终转凉″ 提交于 2020-01-03 15:12:12

问题


I have created a bare git repo (lets call it repo #1) and cloned it.

  • In the clone (repo #2) I have created several folders, one of which I have decided to make a git repo (repo #3).
  • When I commit to repo #2, everything runs as expected exept that repo #3 is ignored (the .git folder, the files commit).

How can I add repo #3 to repo #2 so that when I push repo #2 to repo #1, I can make a seperate clone of repo #1 in which I can also access the history etc. of repo #3?

In other words. How do I create a git repository that contains another git repository?


回答1:


You shouldn't do that. Metadata under .git/ is changed during repo lifetime and that changes not necessarily mean "changes in the content" that should be committed: simple git repack changes files under .git but that changes should not be committed. Why do you want to do that?




回答2:


I don't know how to do exactly what you are suggesting, but sub-modules probably come close (or as close as you are going to get). Here is a decent tutorial:

http://git.or.cz/gitwiki/GitSubmoduleTutorial




回答3:


see git submodule

i’ve never used it, so all i can do is post a link …




回答4:


I'm not a GIT pro by any means, but i think you are referring to git submodules

git submodule --help



回答5:


In your container repository root folder, just do:

git submodule add https://github.com/yourusername/containedrepo.git containedrepo

This will clone the containedrepo inside the /containedrepo directory. From now on, you should not make changes in the /containedrepo directory, but rather make changes in the containedrepo and then pull them. When you pull the main container repository, it will also pull all submodules repository, e.g. containedrepo.git.

Here's a great tutorial : https://github.com/NebuPookins/git-submodule-tutorial



来源:https://stackoverflow.com/questions/1404232/create-a-git-repository-that-contains-another-git-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!