【发布时间】:2017-06-28 22:49:09
【问题描述】:
我需要将两个 Git 存储库合并到一个全新的第三个存储库中。 我按照以下说明进行操作,它们可以正常工作,但结果不是我所期望的。 Merge two Git repositories without breaking file history
看看这个:
母版未对齐。
- 是否可以将所有内容合并到同一个母版上?
- 我想对主人有一个干净的历史记录。
您可以免费使用我的示例存储库在 GitHub 上:
这是我的合并结果。
这是我想要的情况:(画出解决方案!!!)
我是如何走到现在的:
# Assume the current directory is where we want the new repository to be created
# Create the new repository
git init
# Before we do a merge, we have to have an initial commit, so we'll make a dummy commit
dir > Read.md
git add .
git commit -m "initial commit"
# Add a remote for and fetch the old RepoA
git remote add -f RepoA https://github.com/DimitriDewaele/RepoA
# Merge the files from RepoA/master into new/master
git merge RepoA/master --allow-unrelated-histories
# Do the same thing for RepoB
git remote add -f RepoB https://github.com/DimitriDewaele/RepoB
# Merge the files from RepoB/master into new/master
git merge RepoB/master --allow-unrelated-histories
感谢所有帮助!
更新:答案
正确的答案是变基,而不是合并。
代码:
# Rebase the working branch (master) on top of repoB
git rebase RepoB/master
# Rebase teh working branch (master with RepoB) on top op repoA
git rebase RepoA/master
还有一个问题。第二个 repo 失去了父视图。我为此发布了一个后续问题:Merge two Git repos and keep the history
【问题讨论】:
-
您能否更详细地解释您的预期以及有何不同?
-
您在一个主机上拥有一切,我不确定您所说的“对齐”是什么意思 - 尝试从本地删除 RepoA 和 RepoB 遥控器,然后查看图表的样子。
-
我添加了一个“涂漆解决方案”