重用 git 存储库的一部分
我有以下项目设置:
解决方案 A
项目 1
(轻量级组件)项目 2
(包含大量文件并依赖于项目 1
)
解决方案A
是单个 git 存储库。然后我创建了另一个解决方案,发现我可以重用甚至更新项目 1
的功能。所以我的第二个解决方案可能如下所示:
解决方案 B
项目 1
(必须共享!)项目 3
(取决于项目 1
)。
现在我希望 Project 1
成为共享组件。也就是说,每次我从任一解决方案(A
或 B
)更改 Project 1
的源代码时,我都需要更新另一个解决方案因此。
也许这与git的子模块功能有关。但是,我能够使用它的唯一方法是将整个解决方案 A 指定为解决方案 B 的子模块。由于解决方案 A 的规模巨大,这并不是我真正想要的理想结果。我只需要它的一小部分作为子模块。
我知道这在 svn 中是可能的,并且工作原理与我所描述的完全一样:您在 svn:externals
属性中指定外部存储库中的目录。
有什么建议吗?或者也许,我错过了一些东西?
I have the following project setup:
Solution A
Project 1
(a lightweight component)Project 2
(contains a lot of files and depends onProject 1
)
Solution A
is a single git repository. Then I created another solution and found that I could reuse and even update the functionality of Project 1
. So my second solution would probably look like this:
Solution B
Project 1
(must be shared!)Project 3
(depends onProject 1
).
Now I want Project 1
to become a shared component. That is, every time I change the source code of Project 1
from either solution (A
or B
), I need the other one to update accordingly.
Maybe this has something to do the the submodule feature of git. However, the only way I was able to use it is to specify the whole Solution A
as a submodule for Solution B
. This is not really what I want ideally due to enormous size of Solution A
. I only need a tiny part of it to be a submodule.
I know that it's possible in svn and works exactly as I've described: you specify a directory within an external repository in the svn:externals
property.
Any tips on that? Or maybe, I'm missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这肯定与子模块有关(请参阅子模块的性质)
在您的情况下,理想的解决方案是从
SolutionA
Git 存储库中提取Project1
:请参阅如何提取 git 子目录和用它制作一个子模块?。
但这涉及重写 SolutionA 历史,如果您已经发布了它并且有人正在从中撤出,那么这就是一个问题。
使用 filter-branch 进行提取过程。
然后将
Project1
声明为SolutionB
中的子模块:This is definitely related to submodules (see the nature of submodules)
In your case, the ideal solution would be to extract
Project1
fromSolutionA
Git repo:See How to extract a git subdirectory and make a submodule out of it?.
But that involves rewriting SolutionA history, which is a problem if you have already published it and if some people are pulling from it.
Using filter-branch for the extraction process.
Then declare
Project1
as a submodule inSolutionB
:将项目 1 拆分到其自己的存储库,并使其成为解决方案 A 和解决方案 B 的子模块。
Split Project 1 out to its own repository, and make it a submodule of both Solution A and Solution B.