2

At the beginning of the project we started REPO-A. That repo continued for several months until one of the engineers decided to fork the project. Now he did this by just duplicating the directory and starting a new repo. REPO-B. Now B has none of the history from A, and A hasn't had any further development. NOW we want to go back to A and merge everything from B back into A, and keep all the history of B while it was a separate repo. The only saving grace here is that since B started as a copy of A I should be able to graft on B's history right onto the end of A, and everything should be fine.

Unfortunately I've had a helluva time trying to do that.

I tried in (REPO-A):

git add remote new REPO-B
git checkout -b mergeAttempt
git merge -X theirs --allow-unrelated-histories new/master

Now this seems to work slightly, only REPO-B's history now overwrites any of the history that existed from REPO-A on the files that were modified, so there's no true history. So I tried:

git cherry-pick -X theirs <REPO-B first commit>..<REPO-B last commit>

This also fails because REPO-B has several merges between the branches that had been created in it and master. I also tried to create a branch in REPO-B that rebases the root of the repo to the last commit in REPO-A with hilarious consequences.

So I'm not sure where to go from here.

1615903
  • 32,635
  • 12
  • 70
  • 99
Ramon Y
  • 21
  • 1
  • Not sure if the git tooling will easily allow you to do this but you should do a clone of A, then add B as a remote to the clone, fetch B into the clone, then rebase all the commits from B on top of the commits from A. If this works you would have 1 history from A through B. – Lasse V. Karlsen May 29 '17 at 08:12
  • `he did this by just duplicating the directory` : did he copy the whole repo folder ? something like `cp -r project-A/ project-B/` ? – LeGEC May 29 '17 at 09:54
  • It looks that way, but he re-committed it, so the original .git folder from REPO-A was lost. REPO-B thinks it's a fresh repo. – Ramon Y May 30 '17 at 02:54

1 Answers1

3

Steps to merge REPO-A into REPO-B:

cd path/to/REPO-B

git remote add REPO-A path/to/REPO-A

get fetch REPO-A

git merge --allow-unrelated-histories REPO-A/master 

git remote remove REPO-A

Sourced from: git merge different repositories?

Community
  • 1
  • 1
nevihs
  • 991
  • 1
  • 12
  • 23