git 合并两个仓库,并保留历史记录

问题

repo1 repo2是两个无关联的仓库,需要合并并保留两者的提交历史

git checkout repo1 repo1/master
git checkout repo2 repo2/master
git merge repo1

直接尝试合并时会报错

fatal: refusing to merge unrelated histories

解决步骤

  1. 使用参数–allow-unrelated-histories合并
 git merge repo1 --allow-unrelated-histories
  1. 处理冲突文件
    如果存在冲突文件会报信息如下

CONFLICT (add/add): Merge conflict in README.md
Auto-merging README.md
Automatic merge failed; fix conflicts and then commit the result.

修改处理好文件冲突内容后,将文件冲突标记为已解决

  1. 提交所有冲突文件/从repo1合并新增的文件

猜你喜欢

转载自blog.csdn.net/zhoudingding/article/details/128936126