简体   繁体   English

Git功能分支依赖项

[英]Git feature branches dependencies

I looked at several possible solutions on the Internet, but I still can not get it in my head, how it can help in my situation. 我查看了Internet上的几种可能的解决方案,但仍然无法理解它如何对我的情况有所帮助。 We have a variation of git-flow: master branch, dev branch, each new feature is created in a separate branch from dev. 我们有一个git-flow的变体:master分支,dev分支,每个新功能都是在dev的单独分支中创建的。 The problem is that two developers working on one feature are dependent on each other's code. 问题在于,从事一项功能的两名开发人员依赖于彼此的代码。

Suppose this is a project for a microcontroller. 假设这是一个针对微控制器的项目。 One developer writes the system part, manages the memory. 一位开发人员编写系统部分,管理内存。 The second developer writes UI and does not touch the writing of system functions. 第二个开发人员编写UI,并且不涉及系统功能的编写。 It is most logical to assume that everyone should have their own feature branch. 假设每个人都应该有自己的功能分支是最合乎逻辑的。

However, both branches are cross-dependent on each other. 但是,两个分支相互交叉依赖。 To develop a feature, the UI developer needs to call the functions created by the first developer. 要开发功能,UI开发人员需要调用第一个开发人员创建的功能。 To develop the functions, the first developer needs to test them on the resulting UI. 要开发功能,第一个开发人员需要在结果UI上对其进行测试。 In addition, developers must be constantly agreeing on what functions should be created and what signatures they should have - changes made by one developer are needed by the second developer almost instantly because of their close pair work. 此外,开发人员必须始终就应该创建哪些功能以及应该具有哪些签名达成一致-由于一个紧密的配对工作,第二个开发人员几乎立即需要一位开发人员进行更改。

Another example - web-dev with backend developer and frontend developer being dependent on each other changes. 另一个示例-后端开发人员和前端开发人员相互依赖的web-dev。

How can this situation be resolved? 如何解决这种情况?

Integration branch? 整合分支?

I would imagine that a possible solution would be to create an integration branch where updates meet more often. 我想一种可能的解决方案是创建一个集成分支,使更新相遇的频率更高。 If something breaks, anyone can fix it in their development branch and rebase/cherrypick to the integration branch. 如果出现问题,任何人都可以在其开发分支中对其进行修复,然后将base / cherrypick重置为集成分支。

They are also sometimes called "throwaway branches". 它们有时也称为“一次性分支”。

Example

Imagine a clean repository with last commit on the dev branch - D . 想象一下一个干净的存储库,最后一次提交在dev分支D

User F (frontend) creates its own branch frontend-dev on commit D . 用户F(前端)在提交D上创建自己的分支frontend-dev So does the user B (backend) a branch backend-dev on same commit. 用户B(后端)在同一提交时也分支backend-dev

Each user develops its own parts in their respective branches and as they are private branches, everything is allowed, including force pushes. 每个用户都在各自的分支机构中开发自己的零件,并且由于它们是私有分支机构,因此可以进行所有操作,包括强行推动。 And nobody else should commit to their branch. 而且没有其他人应该致力于其分支机构。

After some time, the branches may look like this: 一段时间后,分支可能如下所示:

D - F1 - F2 - F3 - F4 <frontend-dev)
 \
  \ B1 - B2 - B3 <backend-dev)

Once the user F or B needs to test how their work integrate with each other, they create a new branch integration from commit D and accumulate all commits from both respective branches on top of it: 一旦用户F或B需要测试他们的工作如何相互集成,他们就会从提交D创建一个新的分支integration ,并在其顶部累积来自两个相应分支的所有提交:

D - F1 - F2 - F3 - F4 <frontend-dev)
|\
| \ B1 - B2 - B3 <backend-dev)
 \
  \ F1 - F2 - F3 - F4 - B1 - B2 - B3 <integration)

If the backed developer finds a bug, he may create a fix, commit it as a fixup commit (with git commit --fixup ) on the integration branch and test: 如果支持的开发人员发现错误,则可以创建一个修复程序,将其提交为在集成分支上的修复程序提交(使用git commit --fixup )并测试:

D - F1 - F2 - F3 - F4 <frontend-dev)
|\
| \ B1 - B2 - B3 <backend-dev)
 \
  \ F1 - F2 - F3 - F4 - B1 - B2 - B3 - B2Fixup <integration)

Once the developer is happy, he/she may cherrypick all the work to his development branch: 一旦开发人员感到满意,他/她就可以将所有工作分拣到其开发部门:

D - F1 - F2 - F3 - F4 <frontend-dev)
|\
| \ B1 - B2 - B3 - B2Fixup <backend-dev)
 \
  \ F1 - F2 - F3 - F4 - B1 - B2 - B3 - B2Fixup <integration)

And possibly delete the integration branch. 并可能删除integration分支。 To clean up the repository, git rebase --interactive --autosquash dev may be used to achieve: 要清理存储库,可以使用git rebase --interactive --autosquash dev来实现:

D - F1 - F2 - F3 - F4 <frontend-dev)
 \
  \ B1 - B2(withFixup) - B3 <backend-dev)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM