2021-05-20

场景二:从主库发MR到fork库有冲突,怎么解决冲突

问题现象:从主库发MR到fork库有冲突,如何解决

反向合并问题,也就是当主库有更新了,需要将远端主库代码同步到fork的个人仓时,提示有冲突,如何处理?

解决方案:
以上图中的两个仓库为例来解决
主库地址:ssh://git@isource-dg.ztehaha.com:2222/ICP_iSource_OrgTest/DG_0227.git
fork库地址:ssh://git@isource-dg.ztehaha.com:2222/fdd12345/DG_0227.git
分支:均为master
1)clone fork库到本地,并checkout到指定分支
git clone fork库及对应的分支到本地,如fork地址为:ssh://git@isource-dg.huawei.com:2222/fdd12345/DG_0227.git,分支为:master
下载完成后可以使用git remote -v和git branch -a查看仓库地址和分支名是否正确
如果本地已经下载了fork库代码,忽略此步骤

fdd12345@szxy7fdd12345 MINGW64 /d/iSource/TestCode/147/0411
$ git clone ssh://git@isource-dg.huawei.com:2222/fdd12345/DG_0227.git -b master
Cloning into 'DG_0227'...
connected to center DG
remote: Counting objects: 29, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 29 (delta 11), reused 28 (delta 10)
Receiving objects: 100% (29/29), 14.63 MiB | 22.37 MiB/s, done.
Resolving deltas: 100% (11/11), done.
Checking connectivity... done.

fdd12345@szxy7fdd12345 MINGW64 /d/iSource/TestCode/147/0411/DG_0227 (master)
$ git remote -v
origin  ssh://git@isource-dg.huawei.com:2222/fdd12345/DG_0227.git (fetch)
origin  ssh://git@isource-dg.huawei.com:2222/fdd12345/DG_0227.git (push)

fdd12345@szxy7fdd12345 MINGW64 /d/iSource/TestCode/147/0411/DG_0227 (master)
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

2)同步主库代码,会提示“Conflict”,就表示冲突了。

fdd12345@szxy7fdd12345 MINGW64 /d/iSource/TestCode/147/0411/DG_0227 (master)
$ git pull ssh://git@isource-dg.huawei.com:2222/ICP_iSource_OrgTest/DG_0227.git  master
connected to center DG
remote: 对象计数中: 6, 完成.
remote: 压缩对象中: 100% (4/4), 完成.
remote: Total 6 (delta 2), reused 6 (delta 2)
Unpacking objects: 100% (6/6), done.
From ssh://isource-dg.huawei.com:2222/ICP_iSource_OrgTest/DG_0227
 * branch            master     -> FETCH_HEAD
Auto-merging Platform/GUI_AW_CHN.xml
CONFLICT (content): Merge conflict in Platform/GUI_AW_CHN.xml
Automatic merge failed; fix conflicts and then commit the result.

3)解决冲突
本地fork仓库目录任意空白处右键—>TortoiseGit—>Resolve,弹出框中会显示冲突的文件,开发此时可以选择要解决冲突的文件右键。

说明:
Edit conflicts:编辑冲突文件,适用于远端和本地文件冲突时进行手工合并的场景,编辑后Save并点击Mark as resolved按钮
Resolve conflict using 'theirs':用远端主库上的文件覆盖本地文件,即以远端库上的文件为准
Resolve conflict using 'mine':用本地文件覆盖远端主库上的文件,即以本地的文件为准

4)解决冲突后再commit并push

fdd12345@szxy7fdd12345 MINGW64 /d/iSource/TestCode/147/0411/DG_0227 (master|MERGING)
$ git add .
git co
fdd12345@szxy7fdd12345 MINGW64 /d/iSource/TestCode/147/0411/DG_0227 (master|MERGING)
$ git commit -a   (弹出框中按:wq即可保存并退出)
[master 066339b] Merge branch 'master' of ssh://isource-dg.huawei.com:2222/ICP_iSource_OrgTest/DG_0227

fdd12345@szxy7fdd12345 MINGW64 /d/iSource/TestCode/147/0411/DG_0227 (master)
$ git push origin master
connected to center DG
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 1.61 KiB | 0 bytes/s, done.
Total 7 (delta 2), reused 0 (delta 0)
remote: Start Binary Checking for Branch 'master'       [SKIPPED]
remote: Start Git Hooks Checking for Branch 'master'                            [PASSED]
To ssh://git@isource-dg.huawei.com:2222/fdd12345/DG_0227.git
   6c06b2b..066339b  master -> master

这时候主库的代码就全部同步到本地fork的个人库了。

上一篇:创建DG《大话 Oracle Grid》


下一篇:sublime 使用技巧