如何避免多个分支合并的合并冲突?
我正在与一个中等规模的团队一起开发一个网络应用程序。我们正在使用 Git 对该项目进行版本控制/集体编码。在我和我的同事之间,我认为我们即将遇到困难的合并,我想看看在遇到麻烦之前我们是否可以做得更好。
我们主要在 Git 的开发分支上工作:
D-E-F-G
我的同事创建了一个分支来进行重大更改:
A
/
D-E-F-G
然后我将该分支拉下来,修复了其中的一些错误,然后即将将其合并回来。同事为另一个功能启动了一个新分支:
A-B-C-D
/
D-E-F-G-H-I-J
\
A-B-C
现在,我需要创建一个使用同事新分支中的样式的新功能,但他的新分支需要做更多的工作才能合并回开发中,所以我正在从他的分支中分支出来利用他的风格,并在他的东西合并回来时保持一致的外观:
A-B-C-D
/
D-E-F-G-H-I-J
\
A-B-C..
\
A
但是,我们确实还需要他在其他分支中开发的一些风格,所以我正在考虑将开发重新调整到我的分支中将他的另一个分支合并回开发中:
branch 1: A-B-C-D
/ \
develop: D-E-F-G-H-I-J..
\ \
branch 2: A-B-C..\
\ \
branch 3: A-B..
这样,我需要处理的分支将拥有我需要的来自他的两个分支的代码,但将从开发中重新建立基础,以希望减少冲突。我担心的是,当他尝试将分支 2 合并回开发时,他可能会遇到很多问题。他会不会有很多矛盾?我们可以做一些更好的事情吗?
I am working on a web application with a medium sized team. We are versioning/collectively coding this project using Git. Between my co-worker and myself, I think we are about to run into a difficult merge, and I'd like to see if there's anything we can do better before we run into trouble.
We are primarily working in Git on the develop branch:
D-E-F-G
My co-worker created a branch to work on a big change:
A
/
D-E-F-G
Then I pulled that branch down, fixed some bugs in it, and am about to merge it back in. Meanwhile, my co-worker started a new branch for another feature:
A-B-C-D
/
D-E-F-G-H-I-J
\
A-B-C
Now, I need to create a new feature that uses styles from my co-worker's new branch, but his new branch needs a lot more work before it can be merged back into develop, so I'm branching off of his branch to take advantage of his styles and have a consistant look when his stuff gets merged back in:
A-B-C-D
/
D-E-F-G-H-I-J
\
A-B-C..
\
A
But, we really also need some of the styles he developed in his other branch, so I'm thinking of rebasing develop into my branch as soon as we merge his other branch back into develop:
branch 1: A-B-C-D
/ \
develop: D-E-F-G-H-I-J..
\ \
branch 2: A-B-C..\
\ \
branch 3: A-B..
This way, my branch that I need to work on will have the code I need from both of his branches, but will have been rebased from develop to hopefully reduce conflicts. What concerns me is that he may run into a lot of problems when he tries to merge branch 2 back into develop. Will there be a lot of conflicts for him? Is there something better we can do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您遇到的问题是,通过合并您会引入一些您确实想要的更改和一些您不想要的更改。
让你的特征更小。
从一个共同点开始你的功能——无论一开始感觉多么笨拙。
使用 rerere 使重新合并变得更容易。
这在我的按功能分支帖子中进行了总结:
http:// /dymitruk.com/blog/2012/02/05/branch-per-feature/
You are running into issues where by merging you are introducing changes you do want and some you don't want.
Make your features smaller.
Start your features from a common point - no matter how clumsy it feels at first.
Use rerere to make remerging easier.
This is summed up in my branch-per-feature post:
http://dymitruk.com/blog/2012/02/05/branch-per-feature/
对于这个答案,我将从您的解释中假设两件事:
develop
是一个准备部署的分支,它可以接收错误修复提交并可以随时部署(或发布)(如果您不这样做)对此,我强烈建议您这样做:P)。develop
分支上不会有重要的功能。因此,我建议您创建一个名为
feature-integration
的分支,每天(或者当您对develop< /代码> 分支)。然后,当您的同事完成了大部分工作时,他可以将其代码合并到
feature-integration
分支中,您可以在开发中使用它,将feature-integration
重新定位到你的工作分支。您(以及您的同事)还应该使用feature-integration
定期(我建议每天或至少每周)重新调整您的工作分支代码,以保持代码更新并解决一些最终问题开发过程中会发生冲突,因此当您决定将其合并到develop
时,您不会遇到痛苦的合并。For this answer I will assume two things from your explanation:
develop
is a ready-to-deploy branch which can receive bug-fixes commits and be deployable (or released) anytime (if you don't do this, I strongly recommend you to do so :P).develop
branch.So, I would suggest that you create a branch called
feature-integration
that is rebased withdevelop
on a daily basis (or when you have changes on thedevelop
branch). Then, when your colleague does a significant part of his work, he can merge his code intofeature-integration
branch and you can use it on your development rebasingfeature-integration
onto your working branch. You (and your colleague as well) should also keep your working branch code rebased on a regular (I would suggest daily or at least weekly) basis withfeature-integration
to keep your code updated and solve some eventual conflicts during the development, so you shall not have a painful merge when you decide to merge it intodevelop
.