EX: 将仓库A的develop分支代码部分迁移到仓库B的master
-
首先进入终端打开目的仓库B的目录 (cd B)
-
想仓库A的代码提交到仓库B的master分支
-
首先切换分支 git checkout master (目的仓库)
-
将仓库A的地址添加到仓库B中 git remote add 仓库名 https://A.git (目的仓库) (git remote add tobe_merge https://A.git )
-
查看本地的远程仓库 git remote (目的仓库)
-
抓取仓库A的数据到仓库B中 git fetch 仓库名 (目的仓库) (git fetch tobe_merge)
-
创建一个新的分支master_temp,用仓库A的代码在仓库B上新建一个分支,稍后将这个分支的代码和本地代码Merge,这样就可以将仓库A的代码和仓库B中的代码merge了 git checkout -b master_temp 仓库名/仓库A的你想要的代码的分支 (git checkout -b master_temp tobe_merge/develop )
-
切换到仓库B的master分支 (git checkout master)
-
合并代码 (git merge master_temp) (注:如果是合并某个提交 使用git cherry-pick commitid)
-
git push
-
git remote rm 仓库名
9: git cherry-pick commitId1..commitIdn (合并从commitId1到commitIdn,但不包含commitId1,如果要包含git cherry-pick commitId1^..commitIdn) 该过程就是解决冲突(git add ,git commit ,git cherry-pick - -continue)