[英]How to resolve merge conflicts in a monorepo?
Assume the following situation:假设以下情况:
The problem arises when changes (created by separate developers) on a feature branch conflict in both, backend and frontend code.当后端和前端代码中的功能分支上的更改(由单独的开发人员创建)发生冲突时,就会出现问题。 A single developer (given the mentioned assumptions) is not able to conduct an update-merge on his own.
单个开发人员(鉴于上述假设)无法自行进行更新合并。
What is the best practice to resolve merge conflicts which span frontend and backend code?解决跨越前端和后端代码的合并冲突的最佳实践是什么? If the vertical feature-branch based workflow is the underlying problem, how would you improve this setup while sticking with the first three assumptions?
如果基于垂直特征分支的工作流是潜在问题,您将如何在坚持前三个假设的同时改进此设置?
Here is a blunt, technical way to split the merge conflict resolution in two distinct parts :这是将合并冲突解决方案分为两个不同部分的一种直率的技术方法:
from the master
branch, create two phony commits, one which carries only the changes on backend
, one which carries only the changes on frontend
从
master
分支,创建两个虚假提交,一个只承载backend
的更改,一个只承载frontend
的更改
have two developpers merge each branch into feature
让两个开发人员将每个分支合并到
feature
merge feature
into master
将
feature
合并到master
# starting situation :
*--X--*--*--Z <- master # X is the fork point
\ # Z is the tip of branch master
\
*--*--*--T <- feature # T is the tip of branch feature
Run the following commands :运行以下命令:
# from master, create a phony branch for backend :
$ git checkout -b backend master
$ git checkout X -- frontend/ # reset the content of 'frontend/' to its state in commit X
$ git commit
# similarly for fontend :
$ git checkout -b frontend master
$ git checkout X -- backend/
$ git commit
You now have :你现在有:
*--X--*--*--Z------
\ \ \
\ B F # B: tip of backend, F: tip of frontend
\
*--*--*--T
feature
:feature
的两个部分:$ git checkout feature
# have one developper fix conflicts on :
$ git merge backend
# and a second one on :
$ git merge frontend
Note : the merges can happen in any order.注意:合并可以按任何顺序发生。
The situation is now :现在的情况是:
*--X--*--*--Z------
\ \ \
\ B F
\ \ \
*--*--*--T--*--M <- feature
feature
into master
feature
合并到master
As for your workflows, if work on backend
and frontend
should be handled separately, you need to have some rule to reflect this in the branches managed by your developpers.至于你的工作流,如果
backend
和frontend
应该分开处理,你需要有一些规则来反映你的开发人员管理的分支。
@bk2204 gives some directions towards doing this in his answer : keep work on backend separate from work on frontend, merge ASAP. @bk2204 在他的回答中给出了一些指导:将后端工作与前端工作分开,尽快合并。
There are a couple typical approaches to this problem:这个问题有几种典型的方法:
I've personally experienced the first and last of these, and I prefer the former, but depending on your workflow, it may not be possible.我个人经历过第一个和最后一个,我更喜欢前者,但根据您的工作流程,这可能是不可能的。 For example, if you have multiple lines of development (eg, a maintenance and a development branch), the first solution won't solve all your problems, but it may reduce them.
例如,如果您有多个开发线(例如,一个维护和一个开发分支),第一个解决方案不会解决您的所有问题,但可能会减少它们。
Generally, the more you can design your workflow such that the conflicts a developer has to solve are related to code they themselves are working on, the more successful you'll be.通常,您越能设计您的工作流程,使开发人员必须解决的冲突与他们自己正在处理的代码相关,您就会越成功。 Even if other developers in the same area are capable of resolving conflicts there, the developer working on a piece of code will be able to do it faster and be more likely to do it correctly because they're presently working there.
即使同一区域的其他开发人员能够解决那里的冲突,处理一段代码的开发人员也能够更快地完成它,并且更有可能正确地完成它,因为他们目前正在那里工作。
A possible technical approach is using git imerge
and stashing the incremental products somewhere as a ref, then having each developer resume the stashed state.一种可能的技术方法是使用
git imerge
并将增量产品存储在某处作为参考,然后让每个开发人员恢复隐藏状态。 This is likely to be tricky, though, and while possible, isn't recommended.不过,这可能很棘手,虽然可能,但不建议这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.