简体   繁体   中英

Merging two Git repositories

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.

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


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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM