如何解决Gitee提交pr冲突

您所在的位置:网站首页 pr出现事件怎么解决 如何解决Gitee提交pr冲突

如何解决Gitee提交pr冲突

2024-07-07 13:28| 来源: 网络整理| 查看: 265

下面以system_cpu_probe冲突为例,介绍解决冲突的流程。 在这里插入图片描述 在此之前,建议了解一下git基本命令的原理。 图片源自网络可参考: git工作原理及提交规范【干货】 Git 原理入门

解决方案:本地手动同步远程分支,解决冲突

因为创建、合并和删除分支非常快,所以Git鼓励你使用分支完成某个任务,合并后再删掉分支,这和直接在master分支上工作效果是一样的,但过程更安全。

以下步骤,均在本地master分支(即提交Pr的分支)进行。 当然,为安全起见,可以新开一个分支,在此之上进行操作。但后续需要合并(merge)到master分支,再提交,详情可参考廖雪峰的blog:解决冲突。

如果只有一个commit,直接跳到第2步。否则:先尝试合并所有提交的commit为一个,如果不行,查看日志,回退到最初的版本。回退前,保存好后面提交commit的相关改动。 [root@localhost A-Ops]# git log [root@localhost A-Ops]# git reset --hard 尝试同步远程分支 [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 ", 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

可以看到,在与远程分支自动合并gala-gopher/src/probes/system_infos.probe/system_cpu.c时,发生冲突,需要手动解决。在此之后,还需要执行git add/rm ,git rebase --continue。 如果中途遇到任何rebase误操作,可以执行git rebase --bort终止这次rebase。

进入冲突的文件,手动修复冲突 [root@localhost A-Ops]# vim gala-gopher/src/probes/system_infos.probe/system_cpu.c

在这里插入图片描述

接受远程仓库的更新。把原commit代码和无关语句删去,保存退出 在这里插入图片描述对修改后的文件执行add操作 [root@localhost A-Ops]# git add gala-gopher/src/probes/system_infos.probe/system_cpu.c 继续rebase操作。此时会弹出一个编辑页面,保存退出即可。执行成功后如下所示。 [root@localhost A-Ops]# git rebase --continue [detached HEAD 0eafd53] system cpu probe: add 2 metrics, and make some modifications Committer: fenghaiyue 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 [email protected] 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.

在这里插入图片描述

可以按第6步的提示,显式地设置自己的用户名和邮箱,以免出现cla-no [root@localhost A-Ops]# git config --global user.name [root@localhost A-Ops]# git config --global user.email 提交自己的修改 [root@localhost A-Ops]# git commit --amend [master 4352013] system cpu probe: add 2 metrics, and make some modifications Author: fenghaiyue Date: Wed Jul 20 12:04:22 2022 +0800 3 files changed, 82 insertions(+), 15 deletions(-) 强制推送到远程仓库 [root@localhost A-Ops]# git push -f


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3