繁体   English   中英

git:将现有存储库拆分为子模块

[英]git: Split existing repository into submodules

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

这是一个 Java Maven 项目。 目前,一切都在一个 Maven 项目和一个存储库中。 我的目标是实现这样的目标:

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

我可以从当前的 HEAD 创建所有新的东西,但对我来说,提交历史尽可能完整是很重要的。

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

这正是你需要做的。 使用git subtree split <path> -b <branch>将“主”拆分为分支,然后为每个子模块添加远程并将分支推送到远程。

# 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>

设置好所有子模块后,将它们添加到“主”存储库

# add the submodules 
git submodule add <url>

# and once all your submodules are added commit the .gitmodules file
# split the "main repo"
git subtree split -P path -b <branch>

# Create your repository, and get git url

# add remote for branch
git remote add submodule <url>

# push the submodule
git push -u submodule <branch>:master

# remove path
git rm -r path

# Stage and commit changes
git add -A
git commit -m 'Remove <path> for submodule replacement'

# add the submodule 
git submodule add <url> <path>

# and once your submodule is added commit the .gitmodules file 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM