简体   繁体   中英

Git - how to merge multiple repositories with common files?

So my problem is like this: I have 2 different repositories and I need to make a different, new one - containing files from these two. However the repositories share some files (main.c for example) which I want to merge manually... I've tried to merge repos with this tutorial: http://blog.caplin.com/2013/09/18/merging-two-git-repositories/ , however I only get one "copy" of main.c. Maybe I don't understand how git works (I'm pretty new to it), but I really need git to give me two files, which then I can manually change and make into a new main.c... I hope I've made myself clear about my problem... I could just make two different working copies of those repositories, copy the content and make a new repo... But then the history would be lost, right?

Create a repository with TWO remotes using git add remote - http://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes

Clone the first remote to create the initial set of files locally - http://git-scm.com/docs/git-clone

Then use git pull [remote2] to get the files in from the other repository - http://git-scm.com/docs/git-pull

Then resolve any code conflicts.

Then, if desired,add a third remote for the new repo and push the code code to that.

You need to select a central point. For project_a, this will be the default, your code repository in https://path.toyourproject.com/p/project_a . Start by checking it out and moving all of its contents into a subdirectory:

$ git clone https://path.toyourproject.com/p/project_a
$ cd project_a
$ mkdir project_a-cli
$ git mv * project_a-cli
$ git commit -a -m "Move."

Then you're ready to start tackling the merge of a secondary repository. For example, https://path.toyourproject.com/p/project.testers

The first step is to pull in that secondary repository into your central point

$ git remote add origin-testers https://code.google.com/p/project.testers
$ git fetch origin-testers

check it out into a temporary branch and move all of its contents into a subdirectory

$ git branch merge-testers origin-testers/master
$ mkdir project.testers-testers
$ git mv * project.testers-testers
$ git commit -a -m "Move."

Merge the two repositories into one

$ git checkout master
$ git merge merge-testers

Cleanup

$ git branch -d merge-testers
$ git remote remove origin-testers

after that resolve the conflicts manually. you may want to install a visual diff tool for Git.

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