我需要将两个Git存储库合并为一个全新的第三方存储库。
我按照以下说明进行操作,它们有效,但结果并非我所期望的。在不破坏文件历史记录的情况下合并两个Git存储库
看这个:
一个问题尚未解决。第二个仓库丢失了父视图。我发了一个后续问题: 合并两个Git仓库并保留历史记录。
主分支未对齐。
- 是否有可能将所有内容合并到同一个主分支上?
- 我希望主分支上的历史记录保持清晰。
你可以自由地使用我的示例代码库 在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
一个问题尚未解决。第二个仓库丢失了父视图。我发了一个后续问题: 合并两个Git仓库并保留历史记录。