好的,我们有一个包含 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/