将两个类似的远程git回购合并成一个 [英] Merge two similar remote git repos into one

查看:109
本文介绍了将两个类似的远程git回购合并成一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了一些搜索,并通过示例阅读了git书籍和网上的一些地方,例如git,但我无法找到正确的方法来做到这一点。



我有两个git回购站位于两台不同的机器上。这些git仓库中的每一个都保存一个程序的配置。比较两种回购方式时,配置的某些部分是相同的,而有些部分则不相同。

我们想要做的是创建第三个存储库,并将其他两个存储库的内容合并为新的存储库。我希望这样做的目的是让一个存储库拥有来自另外两个仓库的所有数据,但只有其中一个副本。这样,我们希望git能告诉我们两个回购之间有什么不同,并将这些更改合并为一个。



希望这很容易理解。



我试着创建一个新的git仓库,做一个git克隆一个服务器,创建一个新的分支,
做另一个repo的git克隆,然后让git合并它们。我也试过了子树合并,这些都没有产生我想要的。

第一个例子,简单地说删除所有文件并添加一堆新文件。这不是我们想要的,我们希望一个单独的git存储库持有由于将两个远程回购站合并而产生的单一配置副本。



如果任何人都可以提供帮助,这个问题是值得赞赏的。顺便说一句,这两个数据库包含相同的文件,但文件名相同但内容略有不同。

解决方案

如果我们假设回购商被称为A和B,那么您可以先将A或B克隆到C中:


$ b

  $ git clone git://path/to/A.git 

现在C和A相同(A是C的原点)。我们现在可以将B添加为C的远程并创建跟踪B的主分支的追踪分支masterB:

  $ git remote add B git://another/path/to/B.git 
$ git fetch B
$ git checkout --track masterB B / master

现在C的主分支与A的主分支相同,而masterB分支与B的主分支相同。现在我们可以将masterB合并到master :

  $ git checkout master 
$ git merge masterB
$ ..解决冲突

除非您需要跟踪原始存储库,否则我们可以使用以下内容进行清理:

  $ git remote rm origin 
$ git remote rm B
$ git branch -d masterB


Ive done some searches and read a git book and some places on the web like git by example, but I cannot find the correct way to do this.

I have two git repos that sit on two different machines. Each of these git repos holds configuration for a program. When you compare the two repos, some parts of the configuration are identical and some parts are not.

What we want to do is create a third repository, and merge the contents of the other two repositories into this new one. What I hope to achieve by this is to have one repository that has all the data from the other two repos but only have one copy of it. This way, we hope that git will tell us what is different between the two repos and merge these changes together into one.

Hopefully this is easy enough to understand.

I have tried creating a new git repo, doing a git clone of one server, creating a new branch and doing a git clone of the other repo then asking git to merge them. I've also tried the subtree merge and neither of these produced what I wanted.

The first example, simply said remove all files and add a bunch of new files. This isnt what we wanted, we wanted a single git repository holding a single copy of configuration produced as a result of merging the two remote repos together.

If anyone can help with this problem it would be much appreciated.

By the way, both repos data consists of the same files with the same file names but slightly different content.

解决方案

If we assume the repos are called A and B, you could start off by cloning either A or B into C:

$ git clone git://path/to/A.git

Now C is identical to A (and A is the origin of C). We can now add B as a remote to C and create a tracking branch masterB that tracks the master branch of B:

$ git remote add B git://another/path/to/B.git
$ git fetch B
$ git checkout --track masterB B/master

Now the master branch of C is the same as the master branch of A and masterB branch is the same as master on B. We can now merge masterB into master:

$ git checkout master
$ git merge masterB
$ .. solve conflicts

Unless you need to keep track of the original repositories, we can clean up with:

$ git remote rm origin
$ git remote rm B
$ git branch -d masterB

这篇关于将两个类似的远程git回购合并成一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆