技术饭

Gitee代码评审,解决完冲突之后,会自动把目标分支合并到源分支

copylian    0 评论    11599 浏览    2022.04.08

Gitee代码评审,解决完冲突之后,会自动把目标分支合并到源分支,开发项目,使用Gitee的代码评审,合并功能分支feature到dev上的时候,出现了Conflicts,在线解决冲突之后,点击解决合并,结果反向的把dev的分支合并到了feature功能分支,这个源分支多了dev分支的代码。

微信图片_20220408152000.png

微信图片_20220408152029.png

原因分析:

首先了解一下gitee官方提供的解决冲突的几个模式:

Resolve conflicts in interactive mode To resolve less-complex conflicts from the GitLab user interface:

1.Go to your merge request.

2.Select Overview, and scroll to the merge request reports section.

3.Find the merge conflicts message, and select Resolve conflicts. GitLab shows a list of files with merge conflicts.

解释:

1. 转到你的合并请求。

2. 选择Overview,然后滚动到合并请求报告部分。

3. 找到合并冲突消息,然后选择解决冲突。Gitee 显示具有合并冲突的文件列表。冲突突出显示:


注意以下这句关键:

Resolving conflicts merges the target branch of the merge request into the source branch, using the version of the text you chose. If the source branch is feature and the target branch is main, these actions are similar to running git checkout feature; git merge main locally

翻译一下这句就会发现问题了:

解决冲突会使用您选择的文本版本将合并请求的目标分支合并到源分支中。

比如:

如果源分支是 feature,目标分支是main,这些动作类似于在 git checkout feature; git merge main本地运行。

这下就终于理解了,当我的分支是feature/xxxx的时候,解决完冲突,将我的目标分支dev合并到了我的源功能分支上面去了。


解决方案:

方法1:

临时分支替代法:分支feature要合并到dev分支,且出现了冲突,可以先从feature分支拉一个临时分支feature_1,用临时分支feature_temp合并到dev分支

git checkout feature //先切换到feature 分支

git checkout -b feature_1 //拉出来新的分支

git push origin feature_1 //推送到远端

git branch --set-upstream-to=origin/feature_1

然后再gitee界面上面选择feature_1分支去做合并操作


方法2:

回滚补救法:设feature分支要合并到dev分支,且出现了冲突,合并完成后,对feature分支做回滚操作

git log //找到上一个版本的commitID

git reset --hard HEAD/commitID  //强制回退本地分支到上一个版本

git push origin HEAD --force 或者 git push -f origin feature //强制回退远程

参考:巨坑的GitLab在线解决冲突(解决后做了反向合并代码的操作?)

只袄早~~~
感谢你的支持,我会继续努力!
扫码打赏,感谢您的支持!

文明上网理性发言!

  • 还没有评论,沙发等你来抢