【发布时间】:2017-02-17 07:45:38
【问题描述】:
我想补充我的另一个问题:Merge two Git repositories and keep the master history
我已经成功地将 2 个不同的 repo 合并到一个 repo 中。我需要一个变基才能成功地做到这一点。大师是正确的,但我也想保留合并历史。这可能吗?
我有 2 个存储库:
这是变基后的结果。 top repo 的时间是rebase-time。原始日期已丢失!
我就是这样做的:
# 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
# Do the same thing for RepoB
git remote add -f RepoB https://github.com/DimitriDewaele/RepoB
# Rebase the working branch (master) on top of repoB
git rebase RepoB/master
# Rebase the working branch (master with RepoB) on top op repoA
git rebase RepoA/master
有可能有这样的东西吗?(涂漆解决方案!!!)
我想保留原始时间+合并历史。
更新 - 答案
最适合我的答案是使用嫁接点。但其他答案在其他用例中也非常有用。我已经把我的结果加到了github上,大家可以评价一下。
答案 1:最适合我的情况“移植”确实为我揭示了正确的工作答案。
答案 2“LeGEC”中的“替换”选项对于某些用例也有很好的效果。一个异常留给我:
答案 3:值得补充 来自“VonC”的答案。在我的情况下,我无法获得“--preserve-merges working”选项。这可能适用于其他场景,但我没有测试这个furtner。
【问题讨论】:
-
你想保留 repoA 只是为了能够检查它的历史吗?还是 repoA 是一个实时存储库,有新的提交、拉取请求等?
-
@LeGEC 我只想用分支历史来检查历史。新的工作将在生成的 repo 之上发生。
标签: git merge repository rebase