场景二:从主库发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':用本地文件覆盖远端主库上的文件,即以本地的文件为准
补充:
f30001153@F30001153 MINGW64 /e/R21_prj/FTTx_ALL/card (R21_prj|REBASE 29/32)
$ git status
rebase in progress; onto ba60c52de
You are currently rebasing branch 'R21_prj' on 'ba60c52de'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: sfd/src/sfd/platform/02_srv/port/sfd_srv_port.c
modified: sfd/src/sfd/platform/02_srv/port/sfd_srv_port_attr.c
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: sfd/src/sfd/platform/01_mmx/port/sfd_mmx_port.cpp
f30001153@F30001153 MINGW64 /e/R21_prj/FTTx_ALL/card (R21_prj|REBASE 29/32)
$ git add .
f30001153@F30001153 MINGW64 /e/R21_prj/FTTx_ALL/card (R21_prj|REBASE 29/32)
$ git rebase --continue
Applying: 【合入描述】RTU license功能
Applying: 【合入描述】RTU license功能
Using index info to reconstruct a base tree...
M sfd/src/sfd/platform/00_common/pub/sfd_pub_enum_trace.h
M sfd/src/sfd/platform/01_mmx/port/sfd_mmx_port.cpp
M sfd/src/sfd/platform/02_srv/port/sfd_srv_port.c
M sfd/src/sfd/platform/02_srv/port/sfd_srv_port_attr.c
M sfd/src/sfd/platform/03_adp/np/port/sfd_adp_port.c
Falling back to patching base and 3-way merge...
Auto-merging sfd/src/sfd/platform/03_adp/np/port/sfd_adp_port.c
CONFLICT (content): Merge conflict in sfd/src/sfd/platform/03_adp/np/port/sfd_adp_port.c
Auto-merging sfd/src/sfd/platform/02_srv/port/sfd_srv_port_attr.c
CONFLICT (content): Merge conflict in sfd/src/sfd/platform/02_srv/port/sfd_srv_port_attr.c
Auto-merging sfd/src/sfd/platform/02_srv/port/sfd_srv_port.c
Auto-merging sfd/src/sfd/platform/01_mmx/port/sfd_mmx_port.cpp
CONFLICT (content): Merge conflict in sfd/src/sfd/platform/01_mmx/port/sfd_mmx_port.cpp
Auto-merging sfd/src/sfd/platform/00_common/pub/sfd_pub_enum_trace.h
CONFLICT (content): Merge conflict in sfd/src/sfd/platform/00_common/pub/sfd_pub_enum_trace.h
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch' to see the failed patch
Patch failed at 0030 【合入描述】RTU license功能
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
f30001153@F30001153 MINGW64 /e/R21_prj/FTTx_ALL/card (R21_prj|REBASE 30/32)
$ git status
rebase in progress; onto ba60c52de
You are currently rebasing branch 'R21_prj' on 'ba60c52de'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: sfd/src/sfd/platform/02_srv/optic/sfd_srv_optic_cfg.c
modified: sfd/src/sfd/platform/02_srv/optic/sfd_srv_optic_exchange.c
modified: sfd/src/sfd/platform/02_srv/port/sfd_srv_port.c
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: sfd/src/sfd/platform/00_common/pub/sfd_pub_enum_trace.h
both modified: sfd/src/sfd/platform/01_mmx/port/sfd_mmx_port.cpp
both modified: sfd/src/sfd/platform/02_srv/port/sfd_srv_port_attr.c
both modified: sfd/src/sfd/platform/03_adp/np/port/sfd_adp_port.c
f30001153@F30001153 MINGW64 /e/R21_prj/FTTx_ALL/card (R21_prj|REBASE 30/32)
$ git add .
f30001153@F30001153 MINGW64 /e/R21_prj/FTTx_ALL/card (R21_prj|REBASE 30/32)
$ git rebase --continue
Applying: 【合入描述】RTU license功能
Applying: 【合入描述】RTU license功能
Applying: 【合入描述】RTU license功能
f30001153@F30001153 MINGW64 /e/R21_prj/FTTx_ALL/card (R21_prj)
$ git status
On branch R21_prj
Your branch is ahead of 'origin/master' by 32 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
f30001153@F30001153 MINGW64 /e/R21_prj/FTTx_ALL/card (R21_prj)
$ git mm upload
INFO: Start remote sync for objects of project: manifest
manifest> connected to center DG
Changes are found in multiple projects:
+ project FTTx_ALL:
11 commits (Wed May 26 09:32:38 2021 +0800) in branch R21_prj will be published to remote branch master
+ project FTTx_ALL/card:
22 commits (Wed May 26 09:57:51 2021 +0800) in branch R21_prj will be published to remote branch master
You can upload them all, or edit the upload list in a editor (by remove leading comment characters).
Continue uploading? (Yes/No/Edit) y
INFO: Upload project: FTTx_ALL/card
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的个人库了。