如何设置一个 git 结构,其中子模块需要在其下面有一个外部库?
我正在使用 git,我的项目 (MyProject) 已将 github 上托管的公共 git 项目 (SubProject) 添加为子模块,位于其目录结构下。 SubProject 需要在其目录结构下包含一个库 (SomeLibrary)。
现在这很糟糕,因为如果不是 SubProject 要求 SomeLibrary 位于其下方,这将非常简单。因为我已经将 SubProject 添加为 MyProject 的子模块,所以无需再执行任何操作。但是,SomeLibrary 是必需的,并且它不托管在任何 git 存储库中。因此,我将创建一个新的存储库并用其版本号对其进行标记。但将所有这些结合在一起的最佳方法是什么?
一旦 SomeLibrary 位于我为其创建的 git 存储库中,我是否可以将 SomeLibrary 添加为 MyProject 下的子模块,或者它必须是 SubProject 的子模块?如果它是 SubProject 的子模块,那么知道我可能需要随着时间的推移从新的标记版本升级 SubProject,最好的方法是什么?一个示例工作流程确实可以帮助我理解这个问题,因为我很难概念化它的样子。 (例如,我会在做任何事情之前分支 SubProject,还是没有必要,这意味着我可以在 SubProject 下提取 SomeLibrary 并提交...)
I'm using git and my project (MyProject) has added as a submodule a public git project hosted on github (SubProject) underneath its directory structure. SubProject requires a library (SomeLibrary) to be contained underneath its directory structure.
Now that sucks, because if it wasn't for SubProject requiring SomeLibrary to be underneath it, this would be very simple. Because I've already added SubProject as a submodule of MyProject, there'd be nothing more to do. However, SomeLibrary is required and it isn't hosted in any git repository. So I'll create a new repository and tag it with its version number. But what's the best way of tying it all together?
Once SomeLibrary is in a git repository that I create for it, can I add SomeLibrary as a submodule underneath MyProject, or must it be a submodule of SubProject? If it's a submodule of SubProject, what's the best way to do it knowing that I may need to upgrade SubProject from new tagged releases over time? An example workflow would really help me wrap my head around this, because I'm having trouble conceptualizing what it would look like. (e.g. Would I branch SubProject before doing anything, or is that not necessary, meaning I could just extract SomeLibrary underneath SubProject and commit...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用某种构建系统(make、maven、ant、MSBuild 等),也许您可以通过将库放置在父 git 存储库中的某个位置并使构建系统将库复制到子模块来规避整个问题建造时。
否则,您可能必须在子模块中创建分支,添加库并提交,然后在父存储库中提交子模块更改。每当子模块作者生成更新时,您必须将其拉入您的分支(从而在保留库的同时为您提供更新)并在父存储库中提交。但是,如果您想在其他计算机上克隆父 git 存储库并获取正确的子模块内容,则必须将此子模块分支推送到您控制的某个位置(例如,您自己的项目的 github 分支)。因此,子模块需要远程:原始 github 项目(用于从作者那里获取更新)和您的 github 分支(用于推送作者更新与您的库分支的合并)。
If you are using some kind of build system (make, maven, ant, MSBuild, etc.), perhaps you can circumvent the entire problem by placing the library somewhere in the parent git repository and making the build system copy the library to the submodule when building.
Otherwise, you might have to create a branch in the submodule, add the library and commit, and then commit the submodule change in the parent repository. Whenever the submodule author produces an update, you must pull it into your branch (thus giving you the update while retaining the library) and commit in the parent repository. However, if you want to clone the parent git repository on other computers and get the correct submodule contents, you must push this submodule branch to some location that you control (for example, your own github fork of the project). Hence, the submodule will need to remotes: the original github project (for pulling updates from the author) and your github fork (for pushing the merges of the author's updates with your library branch).