Git命令自动将子树项目与子模块合并? [英] Git commands to automatically subtree merge a project with submodules?

查看:481
本文介绍了Git命令自动将子树项目与子模块合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现使用Git,子树合并有子模块的外部项目的最佳方式是什么?但是相关的,它不能回答我的问题。



假设我有我的父项目和我的子项目,其中包含子模块。如何子树将子项目合并到父项目的子目录中,并保持子模块的引用正常工作?



我尝试了如下方法:

  git remote add -f child_remote git://github.com/me/child.git 
git checkout -b child_branch child_remote / master
git子模块init
git子模块更新
git checkout master
git read-tree --prefix = child_directory / -u child_branch

但读取树会丢失子模块,而.gitmodules只出现在子目录中。当我尝试执行git submodule init和git submodule update时,我收到了错误信息,例如在路径'child_directory / submodule_directory'中没有在.gitmodules中找到子模块映射。

我也尝试修改 http://help.github.com/subtree-merge/ 使用子模块,但无济于事。



据我所知,我可以通过手动修改.gitmodules文件来引用正确的路径,或者合并在没有子模块的Child项目中,然后将它们重新添加到Parent项目中,但我认为这两种解决方案都是黑客。我正在寻找一个可以自动运行的实际命令,无需手动编辑任何内容。

为什么不在项目中使用子模块?您现在可以全面使用'git submodule update --recursive`。

另外还有git-slave可以帮助您跨子模块自动执行分支。

I found Using Git, what's the best way to subtree merge an external project that has submodules? but while related, it doesn't answer my question.

Suppose I have my Parent project and my Child project, which contains submodules. How do I subtree merge the Child project into a subdirectory of the Parent project and keep the references to the submodules working?

I've tried things like:

git remote add -f child_remote git://github.com/me/child.git
git checkout -b child_branch child_remote/master
git submodule init
git submodule update
git checkout master
git read-tree --prefix=child_directory/ -u child_branch

But read-tree loses the submodules, and .gitmodules appears only in the subdirectory. When I try to do git submodule init and git submodule update I get errors like "No submodule mapping found in .gitmodules for path 'child_directory/submodule_directory'".

I've also tried to modify the instructions at http://help.github.com/subtree-merge/ to work with submodules, but to no avail.

I understand that I could accomplish this by manually modifying the .gitmodules file to refer to the correct path, or merging in the Child project without submodules and then re-adding them to the Parent project, but I consider both of those solutions to be hacks. I'm looking for the actual commands one would run to get this to work automatically, without having to manually edit anything.

解决方案

Why not use submodules in your project? You could now use 'git submodule update --recursive` across the board.

Also there is git-slave to help you automate branches across submodules.

这篇关于Git命令自动将子树项目与子模块合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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