可以直接在Git子模块中开发吗?
我有两个项目(A 和 B)。他们都使用 Common 项目。我想将 Common 包含到 A & 中B 通过子模块,因为这样我就可以直接将 A 和 B 中的每个提交绑定在一起。 B 他们共同依赖的承诺。
过去我试图让我的团队使用这样的子模块,但我们无法让它顺利工作。我们正在从子模块本身内部开发通用代码&从子模块提交,但我们遇到了很多问题,因此我们恢复将所有项目都放在同一目录下(C:\dev\A、C:\dev\Common)。
我很确定我们不知道子模块应该如何使用,但是如果你不能直接在子模块中开发公共代码,那不是会让开发变得更加困难吗?有人可以解释一下子模块的正确用法吗?
I have two projects (A & B). They both use project Common. I want to include Common into A & B via submodules because then I can directly tie each commit in A & B to which commit they rely on in Common.
In the past I tried to get my team using submodules like this, but we couldn't get it to work smoothly. We were developing Common code from within the submodule itself & committing from the submodule but we ran into so many problems that we reverted to having all projects under the same directory (C:\dev\A, C:\dev\Common).
I'm pretty sure we have no idea how submodules are supposed to be used, but if you can't develop Common code directly in the submodule, doesn't that make it more difficult to develop? Can someone please explain the proper usage of submodules?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以直接从子模块进行开发(正如我在“子模块的真实性质”中解释的那样) ).
但是每次您在子模块中提交某些内容(并将其发布到某个地方)时,您都需要确保也在父存储库中提交。
现在您有两个子模块组织:
(实际上,如果
Common
有自己的依赖项,< code>A 或B
将依赖于“ParentCommon
”,它将引用Common
及其所有直接依赖项)除非您有一个结构命令,其中
Common
必须 是A
的子目录,我会推荐第二个组织,它更接近于您的C: \dev\A
、C:\dev\Common
一个。实际上,我只喜欢一个深度依赖项,对于
ParentA
,我将所有依赖项(直接和间接)列为子模块。这是因为,对于任何尝试管理依赖项的工具,您仍然需要做出以下决策:
A
依赖于X
,它需要Z1 和需要
Z2
的Y
:您想在项目中使用/编译哪个版本的Z
?)A
依赖于X
,它需要Z1
,而A
也选择使用X2
)A
依赖于B
,而B
又依赖于C
,而C
使用...A
!)You can develop directly from a submodule (as I explained in "true nature of submodules").
But each time you commit something in the submodule (and publish it somewhere), you need to make sure to commit as well in the parent repository.
Now you have two submodules organizations:
(Actually, if
Common
had dependencies of its own,A
orB
would depend on "ParentCommon
" which would refer toCommon
and all its direct dependencies)Unless you have a structural imperative where
Common
must be a subdirectory ofA
, I would recommend the second organization, which is closer to yourC:\dev\A
,C:\dev\Common
one.Actually, I prefer only one depth dependencies, where for
ParentA
, I list all dependencies, direct and indirect, as submodules.That is because, with any tool attempting to manage dependencies, you will still need to make decisions on:
A
depends onX
which needsZ1
, andY
which needsZ2
: which version ofZ
do you want to use/compile in your project?)A
depends onX
which needsZ1
, whereasA
also choose to useX2
)A
depends onB
which relies onC
which uses...A
!)子模块并不是像您在这里所希望的那样工作得特别顺利。您可能已经注意到,要在子模块中提交对项目的更改(从 Git v1.7 开始,可能是永久的),您需要:
如果您要同步开发子模块和外部项目,这会很麻烦。就混合代码库时更喜欢稳定的软件配置而不是简单性而言,这是“正确的方法”,但在这种情况下命令序列异常长。
然而,弹出原因堆栈,使用子模块进行同步开发可能表明了几个更大的问题之一:
这些情况都不一定适合您,但这些问题是导致您遇到可怕的锁步子模块更新工作流程的问题之一。当您几乎可以依赖共享库和头文件时,子模块工作得很好,但是有一些令人信服的原因(例如,必须一致的奇怪的编译标志)需要从源代码进行编译。我的方法是解决这些问题(如果它们是真正的根本原因)。
但是,如果不存在这些问题,可能是 git 不适合您。说起来我很痛苦,但这绝对是一种可能性。
Submodules are not something that works particularly smoothly, the way you intend it here. As you've probably noticed, to commit a change to a project in a submodule (as of Git v1.7, probably in perpetuity), you need to:
This is cumbersome if you're developing the submodule and the outer project(s) in lockstep. It's "the right way," as far as preferring stable software configurations over simplicity when mixing codebases, but the command sequence is pathologically long in this case.
Popping the why stack, though, lockstep development with submodules probably indicates one of several larger problems:
None of these cases are necessarily true of you, but these are among the problems that cause the horrible lockstep submodule update workflow you're having. Submodules work pretty well when you could almost rely on shared libraries and header files, but there's some compelling reason (e.g. weird compile flags that must be consistent) to compile from source. My approach would be to fix these problems, if they're the real root causes.
If these problems aren't there, however, it may be that git is the wrong tool for you. It pains me to say it, but this is definitely a possibility.