我可以合并两个内容相似但不共享任何祖先的 Git 存储库吗? [英] Can I merge two Git repositories with similar content, but not sharing any ancestry?
问题描述
我有两个代码库,代码库 1,代码库 2.
I have two code bases, Code base-1, Code Base-2.
我运行命令...
git init
git add .
git commit -m "Initial Commit"
... 在两个存储库(目录)中.
... in both repositories (directories).
代码库 1 和代码库 2 之间存在代码差异.
There are code differences between code base-1 and code base-2.
我无法对它们进行分支,因为它们已经包含大约 0.1% 的差异.文件名相同,但对代码略有修改.
I can't branch them because they already contain differences of about 0.1%. The filenames are the same but there are some slight edits to the code.
有没有办法合并两个存储库之间的差异?
Is there a way to merge the differences between the two repositories?
例如,假设我有以下内容.这就是我的开始.代码库 1 和 2 之间存在细微差别.
For example, let's say I have the following. This is what I am starting out with. There are slight differences between codebase 1 and 2.
[oldest code case]
code-base-1/
code-base-1/.git [git stuff with already created repo]
code-base-1/file1
code-base-1/file2
code-base-2/
code-base-2/.git [git stuff with already created repo]
code-base-2/file1
code-base-2/file2
理想情况下,我可以删除 code-base-2,因为它有点新.
Ideally, I could delete code-base-2 because it is a little newer.
我将如何合并这些代码库,以便最终得到一个带有合并文件的代码库?
How would I merge these code bases, so that I eventually come out with one with the merged files?
推荐答案
问题可能来自以下事实:它们是两个不同的存储库(具有不同的 SHA-1 第一个节点),而不是克隆然后修改的一个存储库.
这意味着 'git fetch
' 可能还不够.
The problem might comes from the fact those are two different repository (with a different SHA-1 first node), and not one repo cloned and then modified.
That means a 'git fetch
' is probably not enough.
您可以简单地使用外部工具(即 Git 的外部工具)将 CB2(代码库 2)的内容合并到 CB1 中,例如问题
You could simply use an external tool (external to Git that is) to merge the content of CB2 (Code-Base-2) into CB1, like WinMerge as suggested in the question "Merging in changes from outside a git repository".
另一种选择是使用一些嫁接技术来完成获取:请参阅问题两个结构相同的 git 存储库在没有任何共同历史的情况下可以合并吗?"
The other option would be using some graft technique to complete a fetch: see the question "Can two identically structured git repos be merged when they have never had any common history?"
$ cd project1
$ git config remote.project2.url /path/to/project2
$ git config remote.project2.fetch 'refs/heads/*:refs/project2/*'
$ git fetch project
加上修改嫁接文件(.git/info/grafts
),将project2的提交链接到project1.
Plus modify the graft file (.git/info/grafts
) to link the commits of project2 to project1.
这篇关于我可以合并两个内容相似但不共享任何祖先的 Git 存储库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!