合并两个Git存储库 [英] Merging two Git repositories

查看:158
本文介绍了合并两个Git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的文件结构的git项目:

  Project_A / files ... 

我有另一个git项目,像这样的文件结构:

  Project_B / 
Project_A / files ...
文件...

现在我想将项目A合并到项目B中,并继续使用项目B作为唯一的存储库。



我尝试使用子树合并,但我得到一个错误,说条目'XXX'重叠'XXX'



有没有办法将项目A合并到项目B并保留所有的提交历史?



感谢您的提前! 您可以做一些事情像这样:



在Project_A中,创建一个新的Project_A子目录并将所有内容混入其中,因此Project_A现在看起来像

  Project_A / 
Project_A / files ...



<然后,在Project_B中:

  git remote add project_A Project_A 
git fetch project_A
git branch project_A project_A / master
git checkout -b merge_trial master
git merge project_A

。 ..并根据需要修复merge_trial(或泡沫,冲洗,重复,直到你得到你想要的冲突/重叠)。

我已经做了一些完全一样的事情这是svn-> git迁移的一部分。


I have a one git project with a file structure like this:

    Project_A/files...

I have another git project with a file structure like this:

    Project_B/
        Project_A/files...
        files...

Now I want to merge Project A into Project B and continue using Project B as the sole repository.

I tried using the subtree merge, but I got an error saying "Entry 'XXX' overlaps 'XXX'"

Is there a way to merge Project A into Project B and retain all of the commit histories?

Thanks in advance!

解决方案

You could do something like this:

In Project_A, make a new Project_A subdirectory and git mv everything into it, so Project_A now looks like

Project_A/
    Project_A/files...

Then, in Project_B:

git remote add project_A Project_A
git fetch project_A
git branch project_A project_A/master
git checkout -b merge_trial master
git merge project_A

... and fix as necessary on merge_trial (or lather, rinse, repeat until you get what you want regarding conflicts/overlaps).

I've actually done something exactly like this as part of an svn->git migration.

这篇关于合并两个Git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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