我想在另一个问题上进一步探讨: 合并两个Git存储库并保留主历史记录
我成功地将2个不同的存储库合并为一个存储库。我需要使用rebase来成功完成此操作。主分支是正确的,但我也希望保留合并历史记录。这可能吗?
我有2个存储库:
这是rebase后的结果。顶部存储库的时间是rebase时间。原始日期已丢失!
这是我的做法:
# 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:在我的情况下最好的工作方式 'graft' 对我来说揭示了正确的工作答案。
答案 2 "LeGEC" 的“replace”选项对于某些用例也会产生良好的结果。但对我来说仍然存在一个异常。
答案 3:值得添加 'VonC' 的答案。在我的情况下,我无法使选项“--preserve-merges”工作。这可能在其他场景中有效,但我没有进行进一步测试。





