git - 将 git 子模块 merge 到主存储库

标签 git git-submodules

好的,我们有一个包含 3 个子模块的存储库。现在我们想将这个子模块 merge 回主存储库,保留所有历史记录(好吧,使用子模块被证明比有用更令人头疼)。我们如何进行?

最佳答案

假设您有以下文件系统(并且假设您只有一个子模块,简单的回答)

myRepoRoot
├── myMainFiles/
└── submodule/

你只需要做:

# Preparing the filesystems
cd submodule
# "submodule" is basically the path where you need your submodule code to be in the new repository,
# e.g. app/code/x/y (<-- in this case you need to create multiple folders ofc, not just one like seen here)
mkdir submodule
git mv file1 file2 dir1 dir2 submodule 
git commit -am "Moved file"

# Actually merging
cd myRepoRoot
git remote add sub url_to_submodule
git fetch sub
git merge sub/master

用文字来解释:你有几棵没有共同提交的树,你只需要 merge 这些树。这就是第二部分所做的。

第一部分只需要确保子模块的文件系统符合您的预期。

关于git - 将 git 子模块 merge 到主存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21328557/

相关文章:

git - 使用 git-p4 导入分支 - 未知修订或路径不在工作树中

git - 禁用 git pull 的密码提示,但不适用于推送

git - .git 文件夹是什么?

git - git repo 的奇怪问题?

Git:多个项目可以使用相同的子模块工作副本吗?

git - 如何从包含子模块的 git 存储库中 rebase git submodule 保留对子模块提交的引用?

Git 自动检测系统代理设置

git - "git pull --all"可以更新我所有的本地分支吗?

Git 子模块工作流程从上游 pull 但推送到自己的存储库

git - Jenkins 和更新 git 子模块