下面以system_cpu_probe沖突為例,介紹解決沖突的流程。
在此之前,建議了解一下git基本命令的原理。可參考:
git工作原理及提交規(guī)范【干貨】
Git 原理入門
解決方案:本地手動同步遠(yuǎn)程分支,解決沖突
因?yàn)閯?chuàng)建、合并和刪除分支非常快,所以Git鼓勵你使用分支完成某個任務(wù),合并后再刪掉分支,這和直接在master分支上工作效果是一樣的,但過程更安全。
以下步驟,均在本地master分支(即提交Pr的分支)進(jìn)行。
當(dāng)然,為安全起見,可以新開一個分支,在此之上進(jìn)行操作。但后續(xù)需要合并(merge)到master分支,再提交,詳情可參考廖雪峰的blog:解決沖突。
- 如果只有一個commit,直接跳到第2步。否則:先嘗試合并所有提交的commit為一個,如果不行,查看日志,回退到最初的版本。回退前,保存好后面提交commit的相關(guān)改動。
[root@localhost A-Ops]# git log
[root@localhost A-Ops]# git reset --hard <最初版本的commit_id>
- 嘗試同步遠(yuǎn)程分支
[root@localhost A-Ops]# git fetch upstream
[root@localhost A-Ops]# git rebase upstream/master
Auto-merging gala-gopher/src/probes/system_infos.probe/system_cpu.c
CONFLICT (content): Merge conflict in gala-gopher/src/probes/system_infos.probe/system_cpu.c
error: could not apply 0d8ab09... system cpu probe: add 2 metrics, and make some modifications
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".
Could not apply 0d8ab09... system cpu probe: add 2 metrics, and make some modifications
可以看到,在與遠(yuǎn)程分支自動合并gala-gopher/src/probes/system_infos.probe/system_cpu.c
時,發(fā)生沖突,需要手動解決。在此之后,還需要執(zhí)行git add/rm <conflicted_files>
,git rebase --continue
。
如果中途遇到任何rebase誤操作,可以執(zhí)行git rebase --bort
終止這次rebase。
- 進(jìn)入沖突的文件,手動修復(fù)沖突
[root@localhost A-Ops]# vim gala-gopher/src/probes/system_infos.probe/system_cpu.c
文章來源:http://www.zghlxwxcb.cn/news/detail-467140.html
- 接受遠(yuǎn)程倉庫的更新。把原commit代碼和無關(guān)語句刪去,保存退出
- 對修改后的文件執(zhí)行add操作
[root@localhost A-Ops]# git add gala-gopher/src/probes/system_infos.probe/system_cpu.c
- 繼續(xù)rebase操作。此時會彈出一個編輯頁面,保存退出即可。執(zhí)行成功后如下所示。
[root@localhost A-Ops]# git rebase --continue
[detached HEAD 0eafd53] system cpu probe: add 2 metrics, and make some modifications
Committer: fenghaiyue <root@localhost.localdomain>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
3 files changed, 82 insertions(+), 15 deletions(-)
Successfully rebased and updated refs/heads/master.
文章來源地址http://www.zghlxwxcb.cn/news/detail-467140.html
- 可以按第6步的提示,顯式地設(shè)置自己的用戶名和郵箱,以免出現(xiàn)cla-no
[root@localhost A-Ops]# git config --global user.name <gitee_id>
[root@localhost A-Ops]# git config --global user.email <your_email>
- 提交自己的修改
[root@localhost A-Ops]# git commit --amend
[master 4352013] system cpu probe: add 2 metrics, and make some modifications
Author: fenghaiyue <root@localhost.localdomain>
Date: Wed Jul 20 12:04:22 2022 +0800
3 files changed, 82 insertions(+), 15 deletions(-)
- 強(qiáng)制推送到遠(yuǎn)程倉庫
[root@localhost A-Ops]# git push -f
到了這里,關(guān)于如何解決Gitee提交pr沖突的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!