tags:

views:

110

answers:

2

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!

A: 

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?

VonC
You mean "subtree merge?" Although I rather like the submerge tree.
ebneter
@ebneter: fixed. I should not answer questions at 6AM ;)
VonC
Project_A is not a submodule of Project_B currently. Two separate development repositories were started by two different teams and now I'm trying to merge my teams repository into theirs, but the different file structure of the projects seem to be causing me some issues.
dirtytofu
+2  A: 

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.

ebneter
Instead of git-mv is there a way to also move my files so that all of my previous commits in Project_A also show up as the new modified structure?I think it has to do something with git-filter-branch, but I haven't tested that command out yet.
dirtytofu
Yes, you could use git filter-branch to accomplish the same thing. git mv might be easier in this case, though. In any event, when you fetch project_A into Project_B, all the history will come with it.
ebneter