git:将现有存储库拆分为子模块 [英] git: Split existing repository into submodules

查看:116
本文介绍了git:将现有存储库拆分为子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仅找到有关如何使用git子树拆分存储库的答案.但是,我明确需要子模块.

I only found answers on how to use git subtrees to split up a repository. However, I explicitly want submodules.

这是一个Java Maven项目.当前,所有内容都在一个Maven项目和一个存储库中.我的目标是实现以下目标:

It's a Java maven project. Currently, everything is in one maven project and one repository. My goal is to achieve something like this:

根存储库应包含主要的pom.xml,系统文档等 然后应该有几个子模块,一个用于实用程序库,一个用于主应用程序,依此类推.子模块是它们自己的maven项目,从根存储库中的主maven项目引用.根存储库将不包含任何源代码.

The root repository should contain the main pom.xml, system documentation, etc Then there should be a few submodules, one for a utility library, one for the main application, and so on. The submodules are their own maven project, referenced from the main maven project in the root repository. The root repository will not contain any source code.

我可以从当前HEAD创建所有新内容,但是对我来说重要的是,提交历史记录应尽可能完整.

I could create everything new from current HEAD, but it is important to me that the commit history is kept as complete as possible.

推荐答案

我仅找到有关如何使用git子树拆分存储库的答案.但是,我明确需要子模块.

I only found answers on how to use git subtrees to split up a repository. However, I explicitly want submodules.

这正是您需要做的.用git subtree split <path> -b <branch>将"main"分成多个分支,然后为每个子模块添加远程,然后将分支推送到远程.

Thats exactly what u need to do. Split the "main" into branches with git subtree split <path> -b <branch> and then add remote for each submodule and push the branch to the remote.

# split the "main repo"
git subtree split -P path -b <branch1>

# For each branch that you extract

# add remote for branch 1
git remote add submodule1 <url>

# push the submodule
git push submodule1 <branch>

设置完所有子模块后,将它们添加到主"存储库中

Once you have all your submodules set up add them to the "main" repo

# add the submodules 
git submodule add <url>

# and once all your submodules are added commit the .gitmodules file

这篇关于git:将现有存储库拆分为子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆