另一个 git 存储库中的 Git 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3456888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git repository inside another git repository
提问by beagleknight
I have the following directories structure:
我有以下目录结构:
- g1/
- .git
- a
- b
- c/
- .git
- d
- e
- 1/
- .git
- 一种
- 乙
- C/
- .git
- d
- 电子
As you can see, I have de repository "c" inside repository "g1". When I use the following command:
如您所见,我在存储库“g1”中有一个存储库“c”。当我使用以下命令时:
git clone g1 g2
git clone g1 g2
I only get the following directories structure:
我只得到以下目录结构:
- g1/
- .git
- a
- b
- c/
- 1/
- .git
- 一种
- 乙
- C/
The directory "c" remains empty. Any ideas?
目录“c”保持为空。有任何想法吗?
回答by Jungle Hunter
Submodules(discussed in the Pro Git Book), helps manage repositories nested within a main repository:
子模块(在Pro Git Book 中讨论)有助于管理嵌套在主存储库中的存储库:
Submodules allow foreign repositories to be embedded within a dedicated subdirectory of the source tree, always pointed at a particular commit.
They are not to be confused with remotes, which are meant mainly for branches of the same project; submodules are meant for different projects you would like to make part of your source tree, while the history of the two projects still stays completely independent and you cannot modify the contents of the submodule from within the main project.
Submodules maintain their own identity; the submodule support just stores the submodule repository location and commit ID, so other developers who clone the superproject can easily clone all the submodules at the same revision.
子模块允许将外部存储库嵌入到源树的专用子目录中,始终指向特定的提交。
不要将它们与遥控器混淆,遥控器主要用于同一项目的分支;子模块适用于您希望成为源代码树一部分的不同项目,而这两个项目的历史仍然保持完全独立,您无法从主项目中修改子模块的内容。
子模块维护自己的身份;子模块支持仅存储子模块存储库位置和提交 ID,因此其他克隆超级项目的开发人员可以轻松克隆同一修订版的所有子模块。
回答by VonC
Git 2.5+ (Q2 2015) will be a bit more precise in how it present submodule.
Since a submodule is registered as a gitlink(a special entry in the index), that explains why 'c
' is empty when the parent repo is cloned.
See also "git submodule
checks out the same commit".
You need a git submodule update --init
to fill-up 'c
'.
Git 2.5+(2015 年第二季度)在如何呈现子模块方面会更加精确。
由于子模块注册为gitlink(索引中的特殊条目),这就解释了为什么c
在克隆父存储库时“ ”为空。
另请参阅“git submodule
检出相同的提交”。
你需要一个git submodule update --init
来填充' c
'。
That is now more clearly documented.
现在更清楚地记录了这一点。
See commit ec48a76(27 May 2015) by Stefan Beller (stefanbeller
).
(Merged by Junio C Hamano -- gitster
--in commit 7df5c97, 11 Jun 2015)
请参阅Stefan Beller ( ) 的commit ec48a76(27 May 2015 )。(由Junio C Hamano合并-- --在提交 7df5c97 中,2015 年 6 月 11 日)stefanbeller
gitster
submodule
doc: reorder introductory paragraphsIt's better to start the man page with a description of what submodules actually are, instead of saying what they are not.
submodule
doc:重新排列介绍性段落最好在手册页开始时描述子模块实际上是什么,而不是说它们不是什么。
The git submodule
man pagenow (June 2015) starts with:
该git submodule
手册页开始与现在(2015年6月):
A submodule allows you to keep another Git repository in a subdirectory of your repository.
The other repository has its own history, which does not interfere with the history of the current repository.
This can be used to have external dependencies such as third party libraries for example.When cloning or pulling a repository containing submodules however, these will not be checked out by default; the '
init
' and 'update
' subcommands will maintain submodules checked out and at appropriate revision in your working tree.
子模块允许您在存储库的子目录中保留另一个 Git 存储库。
另一个存储库有自己的历史记录,不会干扰当前存储库的历史记录。
这可用于具有外部依赖项,例如第三方库。然而,当克隆或拉取包含子模块的存储库时,默认情况下不会检出这些;'
init
' 和 'update
' 子命令将在您的工作树中维护已检出和适当修订的子模块。