开发者

Merging two Git repositories

开发者 https://www.devze.com 2022-12-19 13:30 出处:网络
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:

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 'X开发者_JAVA百科XX' 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.


If projectB already contains projectA as a submodule, you should:

  • first remove projectA as a submodule to projectB
  • then try a subtree merge

If projectA was not a submodule of projectB, I would recommend fetching projectA into projectB repo, and then use the graft technique to link the two commit lines together, while not dealing with all the merge conflicts a classical merge would have involved.

See question Git question: possible to merge two different by equal repositories?

0

精彩评论

暂无评论...
验证码 换一张
取 消