Git将子模块合并到父树中并保持提交历史记录 [英] Git merge submodule into parent tree cleanly and preserving commit history
问题描述
我有一个有两个子模块的存储库,我想将其转换为单个项目。很多答案都涉及脚本,有些似乎过于复杂。
[submodulesite]
path = wp- content / themes / site
url = https://ajf-@bitbucket.org/ajf-/site.git
fetchRecurseSubmodules = true
ignore = all
[submodulewpsite ]
path = wp-content / themes / wpsite
url = https://ajf-@bitbucket.org/ajf-/wpsite.git
fetchRecurseSubmodules = true
忽略= all
是否有官方支持/记录的方式将这些子模块合并到父库中? p>
最好的方法是做子树合并。
首先,从您的超级项目中删除子模块和相关配置;编辑您的.gitmodules文件以删除受影响的子模块,或者如果您打算合并所有子模块,则完全删除该文件。删除子模块目录。
接下来,将子模块存储库添加为适合您的超级项目的远程模块:
git remote add site https://ajf-@bitbucket.org/ajf-/site.git
git remote add wpsite https://ajf-@bitbucket.org/ajf - / wpsite.git
然后,取回遥控器:
git fetch --all
现在,从每个子项目中检查出想要移植到主项目的分支:
git checkout -b site-branch site / some_branch
git checkout -b wpsite-branch wpsite / some_other_branch
你现在准备将这些分支合并到你的主项目中:
git read-tree --prefix = site / -u site-branch
git read-tree --prefix = wpsite / -u wpsite-branch
你完成了。用 gitk --all
检查结果。
由于您想转换为单个项目,不会独立更新子项目,所以我不打算描述它是如何工作的。
I have a repository with two submodules that I want to convert into a single project. Many answers involve scripts, and some seem to be overcomplicated.
[submodule "site"]
path = wp-content/themes/site
url = https://ajf-@bitbucket.org/ajf-/site.git
fetchRecurseSubmodules = true
ignore = all
[submodule "wpsite"]
path = wp-content/themes/wpsite
url = https://ajf-@bitbucket.org/ajf-/wpsite.git
fetchRecurseSubmodules = true
ignore = all
Is there an officially supported / documented way to merge these submodules into the parent repository?
The best approach is to do subtree merging.
First, remove the submodules and related configuration from your superproject; Edit your .gitmodules file to remove the submodules affected, or delete the file entirely if you intend to merge all submodules. Delete the submodule directories as well.
Next, add the submodule repositories as proper remotes to your superproject:
git remote add site https://ajf-@bitbucket.org/ajf-/site.git
git remote add wpsite https://ajf-@bitbucket.org/ajf-/wpsite.git
Then, fetch the remotes:
git fetch --all
Now, check out the branches that you want to graft to your main project from each sub-project:
git checkout -b site-branch site/some_branch
git checkout -b wpsite-branch wpsite/some_other_branch
You're now ready to merge those branches as subtrees with your main project:
git read-tree --prefix=site/ -u site-branch
git read-tree --prefix=wpsite/ -u wpsite-branch
And you're done. Check the result with gitk --all
.
Since you want to convert into a single project, you're not going to update the subprojects independently, so I'm not going to describe how that works.
You can read up on this in the chapter on subtree merging from Pro Git
这篇关于Git将子模块合并到父树中并保持提交历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!