xzhuz / blog-gitment

博客备份和comment记录
https://meisen.pro
0 stars 0 forks source link

Git合并两个仓库 #22

Open xzhuz opened 6 years ago

xzhuz commented 6 years ago

https://meisen.pro/article/5a7c6cc7a1aa4013b35bc3eab9e953e9

目前有两个仓库 repo1 和 repo2 两个仓库不一样,现在有个需求需要合并,现在就进行下面的步骤

  1. 将repo1作为远程仓库,合并到repo2中,这是别名other
➜  repo2 git:(master) git add remote other ../repo1.git
  1. 获取远程仓库repo1抓取数据到本地仓库repo2
➜  repo2 git:(master) git fetch other
  1. 将repo1抓取到master数据作为新分支checkout到本地, 新分支命名为repo1
➜  repo2 git:(master) git checkout -b repo1 other/master
  1. 检出repo2的master分支到本地
➜  repo1 git:(master) git checkout master
  1. 合并repo1分支到repo2
➜  repo2 git:(master) git merge repo1

接下来,解决合并后的文件冲突。commit之后就可以push到远程仓库了。