我的项目场景:
开发我的项目的时候,应用gitLab合并性能分支feature到dev上的时候,呈现了Conflicts,在线解决抵触之后,点击解决合并,后果反向的把dev的分支合并到了feature性能分支,这波蜜汁操作过后我就懵了!!!
问题形容
gitLab合并解决抵触之后,反向将指标分支合并到了源分支。
起因剖析:
首先理解一下gitlab官网提供的解决抵触的几个模式:
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.
- Find the merge conflicts message, and select Resolve conflicts. GitLab shows a list of files with merge conflicts.
简略翻译一下就是:
**1. 转到你的合并申请。
- 抉择Overview,而后滚动到合并申请报告局部。
- 找到合并抵触音讯,而后抉择解决抵触。GitLab 显示具备合并抵触的文件列表。抵触突出显示:**
看到这如同感觉也没发现啥问题,接着持续往下看:
留神以下这句要害:
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合并到了我的源性能分支下面去了,oh shit 这该死的操作!!!!!
解决方案:
办法1:长期分支替代法:分支feature要合并到dev分支,且呈现了抵触,能够先从feature分支拉一个长期分支feature_temp,用长期分支feature_temp合并到dev分支。
git checkout feature //先切换到feature 分支git checkout -b feature_temp //拉进去新的分支git push origin feature_temp //推送到远端git branch --set-upstream-to=origin/feature_temp
而后再gitlab界面下面抉择feature_temp分支去做合并操作。
办法2:回滚补救法:设feature分支要合并到dev分支,且呈现了抵触,合并实现后,对feature分支做回滚操作。
git log //找到上一个版本的commitIDgit reset --hard HEAD/commitID //强制回退本地分支到上一个版本git push origin HEAD --force 或者 git push -f origin feature //强制回退近程
这样就轻松解决了gitlab解决抵触后的反向操作,还是要多看看官网文档,贴一下地址gitLab官网文档,心愿大家多多反对和关注。