本文介绍的是在两个不同的仓库上的分支进行衍合,并保留版本的提交的历史和日志
远程库一:develop
远程库二:other
目的:把other分支衍合到develop分支。
步骤:
1、从远程库地址一拉下代码到本地,存放地址如:d:/workspace/develop;
git clone [代码仓库地址一]
2、从远程库地址二拉下代码到本地,存放地址如:d:/workspace/other
git clone [代码仓库地址二]
3、进入other本地分支,创建新分支命名为:common,把common分支reset到最早的一个版本,是回到两个分支最近的共同祖先(基线);
git checkout -b coommon
git reset --hard [commit-id]
此时,other文件夹下有other分支和common分之
4、进入develop,将other作为develop的远程仓库设置别名branch
git remote add branch d:/workspace/other
5、从other仓库同步代码到develop仓库
git fetch branch
6、切换到branch的other分支
git checkout branch/other
7、执行衍合命令,把other分之衍合到develop分之
git rebase --onto develop branch/common develop/other
如果执行命令后提示有代码冲突,先解决冲突,然后执行git status查看修改的文件再git add命令添加到暂存区,再执行git rebase --continue继续衍合知道完成衍合
8、完成衍合后创建新分支,分支名为:new-branch
git checkout -b new-branch
9、提交新分支new-branch到远程develop的仓库
git push origin new-branch