避免代码合并冲突_避免合并冲突-情节提要版

避免代码合并冲突

情节提要参考和交流可以节省一天 (Storyboard References and Communication Save the Day)

I recently worked on a 1-week quick prototype project with a few junior developers. Most of the developers on the team preferred that we use storyboards because it’s what they’re most familiar with.

我最近与几个初级开发人员一起进行了为期1周的快速原型项目。 团队中的大多数开发人员更喜欢我们使用情节提要,因为这是他们最熟悉的。

Though I’m one that prefers working in storyboards, I was not looking forward to the incessant merge conflicts. Meeting after meeting of “which side do I pick?” — storyboards are written in XML if you didn’t know (right-click a storyboard file -> Open As -> Source Code if you want to see for yourself). This makes it difficult for some developers who aren’t familiar with XML to decipher what’s what.

尽管我是一个更喜欢在情节提要中工作的人,但我并不希望不断出现合并冲突。 “我选哪一边? —如果您不知道,情节提要是以XML编写的(如果要自己查看,请右键单击情节提要文件-> 打开方式->源代码 )。 对于一些不熟悉XML的开发人员来说,这很难解释什么。

好消息是……在一周结束时,我们……合并冲突。 只有一个。 这是我们的工作方式… (The Good News Is… At The End Of The Week, We Had… One Merge Conflict. Just one. Here’s how we did it…)

One thing you’ll notice throughout this story is you’re going to hear a lot of “we” as opposed to “I”. That’s because teamwork is paramount to avoiding merge conflicts, and we truly worked as a unit. That’s not to say someone wasn’t the lead — a team needs a leader, after all, someone to provide direction.

在整个故事中您会注意到的一件事是,您将听到很多“我们”而不是“我”。 这是因为团队合作对于避免合并冲突至为重要,而我们确实是一个整体。 这并不是说某人不是领导者–团队需要领导者,毕竟,有人需要提供指导。

When I say we had one merge conflict related to storyboards, I don’t mean one merge conflict that we couldn’t figure out. I mean one merge conflict. Period. We had more merge conflicts related to what I refer to as “greedy” lines of code. That is to say lines of code we don’t agree with others on, and change or lines we change to shortcut something for our own development experience and forget to change back before merging into a common branch.

当我说我们有一个与情节提要相关的合并冲突时,我并不是说我们无法弄清一个合并冲突。 我的意思是合并冲突。 期。 与我所说的“贪婪”代码行有关的合并冲突更多。 就是说,我们不同意的代码行,或更改或更改我们的行来为自己的开发经验捷径,而在合并到公共分支之前忘了更改。

每个开发人员都有自己的分镜脚本,每个开发人员都有自己的分支 (Each Developer Gets Their Own Storyboard, Each Developer Gets Their Own Branch)

The size of the storyboards is up to you and your team, but the less that’s going on in each storyboard, the less of a chance there is for a merge conflict. Two of our storyboards only had one View Controller each!

故事板的大小取决于您和您的团队,但是每个故事板中发生的事件越少,合并冲突的机会就越少。 我们的两个情节提要板每个只有一个View Controller!

We may have gone a little overboard with branches, but the strategy worked. We had a master branch, a common develop branch, and each of us had personal branches. I organized my personal branches by feature, some went by day, some seemed to have no coherent strategy for their personal branch strategy. One thing we all agreed on was that the common branches needed to remain as clean and up to date as possible.

我们可能在分支机构方面有些过分,但是该策略有效。 我们有一个主分支,一个公共开发分支,每个人都有个人分支。 我按功能组织了我的个人分支机构,有的是日常工作,有的似乎对其个人分支策略没有统一的策略。 我们都同意的一件事是,公共分支机构需要保持尽可能干净和最新的状态。

We each picked an MVP feature to own. None of the MVP features resided in just one storyboard, so occasionally, it was necessary to delve into someone else’s storyboard file. That said, each file had an “owner”. This person was responsible for knowing what should be going on with that storyboard. That doesn’t mean whatever they said was what happened, it just means that was the point of contact for working in that file.

我们每个人都拥有一个MVP功能。 MVP功能没有一个驻留在一个情节提要中,因此偶尔需要深入研究其他人的情节提要文件。 也就是说,每个文件都有一个“所有者”。 此人负责了解该故事板应如何处理。 这并不意味着他们说的是发生了什么,仅意味着这是处理该文件的联系点。

Image for post

So if Developer A wanted to work in Developer B’s storyboard file, Developer A would shoot them a message on Slack, and say “Hey, I’m working on feature X, and I need to work in your storyboard file. Is that ok?” Then they would wait for Developer B to respond before even starting to work in the storyboard file in their own branch.

因此,如果开发人员A要使用开发人员B的情节提要文件,则开发人员A会在Slack上向他们发送一条消息,然后说:“嘿,我正在使用功能X,我需要处理您的情节提要文件。 那样行吗?” 然后,他们将等待开发人员B响应,甚至开始在自己分支的情节提要文件中工作。

This is key takeaway number 1. Developer B owns the file and should know if Developer C is working on it (or obviously if they’re working on it). They can then let Developer A know to hold off because someone else is making changes to that file.

这是关键要点编号1。开发人员B拥有文件,并且应该知道开发人员C是否正在处理该文件(或者显然他们是否正在处理该文件)。 然后他们可以让开发人员A知道推迟执行,因为其他人正在对该文件进行更改。

Let’s say Developer C was working on this particular storyboard file at the time. When they’re done, what they’re going to do is commit their work, pull down from the main develop branch, handle any conflicts (if there were any) in their own branch, then push up to the common develop branch. If there were any question whatsoever about what line of code to pick in a conflict, a meeting would be held between any involved parties, but normally we’d already have it figured out beforehand because we talked about it.

假设开发人员C当时正在处理此特定的故事板文件。 完成后,他们要做的是提交工作,从主开发分支中撤出,在自己的分支中处理任何冲突(如果有),然后向上推进到通用开发分支。 如果对在冲突中选择哪种代码行存有任何疑问,将在任何相关方之间举行会议,但是通常我们已经事先弄清楚了,因为我们已经讨论过了。

Before they push up though, they’d let everyone know that their changes were being pushed up to the common develop branch so everyone had an opportunity to review their changes if they wanted to — though we rarely needed to.

但是,在推销之前,他们会让每个人都知道他们的更改已被推到通用开发部门,因此每个人都有机会(如果我们愿意)查看他们的更改-尽管我们很少需要这样做。

At the end of the day, we’d review the common develop branch together and decide if it was clean enough to push up to Master.

归根结底,我们将共同审查通用开发分支,并确定它是否足够干净以提升到Master。

Image for post

You may be wondering, “ if there’s as little as possible going on in each storyboard, and sometimes a storyboard only has 1 View Controller, how do you handle segues?”

Ÿ欧可能会想,“如果有尽量少在各个分镜图下去,有时一个故事板只有1视图控制器,你如何处理塞格斯?”

We didn’t handle any segues programmatically except for a conditionally presented login view. We used Storyboard references for the rest of the project

除了有条件显示的登录视图外,我们没有以编程方式处理任何问题。 我们在项目的其余部分中使用了Storyboard参考

Image for post
An example of a project using Storyboard References
使用情节提要参考的项目示例
Image for post
Image for post
Image for post

清晰的沟通+情节提要参考+合并策略=轻松解决冲突 (Clear Communication + Storyboard References + Merge Policy = Easy Conflict Resolution)

Is all of this necessary to avoid merge conflicts? Honestly, probably not.

所有这些都是必要的,以避免合并冲突吗? 老实说,也许不是。

By communicating clearly, you can avoid merge conflicts before they even start. If everyone knows their role, and no two people have a conflicting role or people who do have conflicting roles discuss who will be owning what, a lot of merge conflicts are prevented.

通过清楚地沟通,您可以避免合并冲突甚至开始。 如果每个人都知道自己的角色,并且没有两个人有冲突的角色,或者确实有冲突的人讨论谁将拥有什么,那么可以避免很多合并冲突。

By using multiple storyboards, and again, each person knowing their role — a lot of conflict is avoided.

通过使用多个情节提要板,每个人都知道自己的角色,避免了很多冲突。

By having a clear merge policy that everyone agrees on and utilizes as it should be, we all have the confidence that what we’re about to push up to a common branch isn’t going to cause catastrophic changes to the project.

通过制定清晰的合并政策,每个人都应同意并利用它,我们所有人都有信心,我们将要推进到一个公共分支的项目不会对项目造成灾难性的变化。

I’m not saying if you do all of these things I mentioned in this article, you won’t have any merge conflicts, but I’m willing to bet you’ll have a whole lot less.

我并不是说,如果您执行了本文中提到的所有这些操作,则不会有任何合并冲突,但是我敢打赌,您的工作量会少很多。

I’d love to hear what you think in the comments.

我很想听听您在评论中的想法。

翻译自: https://medium.com/swlh/avoid-merge-conflicts-storyboard-edition-2a02ceadaf6c

避免代码合并冲突

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值