简体   繁体   English

新开发项目的Git工作流程

[英]Git workflow for a new dev project

I am starting a new Project and it has been decided that we shall use git for our version control. 我正在启动一个新项目,并且决定将git用于我们的版本控制。

It is a project which involves development of multiple components / Microservices from scratch. 这是一个涉及从头开始开发多个组件/微服务的项目。

To address the complexities in our organisation where we have junior developers, senior developers, dev leads, architects etc., I was looking to use a git workflow based more or less on gitflow, so that we can ensure that developers can work on feature branches and before moving on to the develop branch, we have some code review process in place. 为了解决我们拥有初级开发人员,高级开发人员,开发主管,架构师等的组织中的复杂性,我一直在寻找使用或多或少基于gitflow的git工作流,以便确保开发人员可以在功能分支上工作在进入开发分支之前,我们已经进行了一些代码审查过程。 I want to have master branch which corresponds to the production / production ready code and release branches to signify the current release in progress. 我想拥有与生产/生产就绪代码相对应的master分支和release分支,以表示当前正在进行的发行。

It is an agile project so my idea is to have develop branch corresponding to the sprint code (unit tested and reviewed) and the release branch corresponding to the release (=3 sprints). 这是一个敏捷项目,所以我的想法是拥有一个与sprint代码相对应的development分支(已测试和审查的单元)和一个与发行版相对应的release分支(= 3个sprint)。

The only issue I am facing is how to define the master branch and the relationship between master and develop at the beginning. 我面临的唯一问题是如何在开始时定义master分支以及master与development之间的关系。

Since it is a new dev project, we begin with no production code and everything would basically start from feature branches, move to develop, release and then the master when we have the production ready code. 由于这是一个新的dev项目,因此我们从没有生产代码开始,并且基本上所有东西都将从功能分支开始,然后转移到开发,发布,再到拥有生产就绪代码的母版。

Any suggestions on how to handle this in a good way and also, is this a good idea 关于如何以良好方式处理此问题的任何建议,也是一个好主意

Thanks in advance 提前致谢

First create a master branch and then from the master branch create other branches. 首先创建一个master分支,然后从master分支创建其他分支。 For your reference, I find this gitflow branching model diagram helpful and have successfully in multiple projects. 供您参考,我发现 gitflow分支模型图很有用,并且在多个项目中均成功。

Don't over do it. 不要结束。 First start off with the simplest branching strategy and then depending upon the complexity and need you may create or adapt to more complex branching strategy. 首先从最简单的分支策略开始,然后根据复杂性和需要,您可以创建或适应更复杂的分支策略。

I think gitflow is just fine for a project as you describe it. 我认为gitflow对于您所描述的项目来说就很好。

If you just start, I would create the master but leave it empty. 如果您只是开始,我将创建master但将其保留为空。 The develop can be filled with static files (.gitgnore or something like that). 可以用静态文件(.gitgnore或类似的文件)填充develop Then you start developing in feature branches and merge to develop . 然后,您开始在feature分支中进行develop并合并以进行develop After three sprints you create a release branch and do your extended tests. 经过三个冲刺后,您将创建release分支并进行扩展测试。

After all tests pass and you are willing to release your code, you merge into master . 在所有测试通过并愿意发布代码之后,您将合并为master So you first merge to master after three months from now. 因此,从现在开始三个月后,您将首先合并为母版。

First, if you're asking this question, you're going to want to start off with a clean, simple flow, then once everyone on the team is rowing ahead well, you can consider incorporating additional branches or level. 首先,如果您要问这个问题,那么您将要以干净,简单的流程开始,然后,一旦团队中的每个人都顺利前进,您可以考虑合并其他分支或级别。 Don't be surprise if you find you don't need any! 如果您发现不需要任何东西,请不要感到惊讶! It can be a non-trivial task trying to keep separate parallel branches all in sync, with an understandable commit log when you're cherry picking features between them. 尝试使单独的并行分支保持全部同步,并且当您在它们之间挑选功能时,具有易于理解的提交日志,这可能是一项艰巨的任务。

NOTE: the squash merges below are for only finished features being merged into master . 注意:以下壁球合并仅适用于将完成的特征合并到master中 As you develop a feature, if you periodically need to update your feature branch from master, don't squash your update merges from master. 开发功能时,如果您定期需要从master更新功能分支, 请不要从master 压榨更新合并

Some folks prefer keeping individuals sub-commits of each feature branch when merging back into master. 一些人更喜欢在合并回母版时让每个子分支的个人子提交。 I don't, but feel to exclude the squashing, it does't chage the workflow. 我没有,但是要排除挤压,它不会浪费工作流程。

I suggest you use this simple flow: 我建议您使用以下简单流程:

  • HEAD of master is for all intents develop HEAD主是所有意图develop
  • All development happens on feature branches cut from the HEAD of master (unless it's a patch for a release branch) 所有开发都发生在从master的HEAD切下的功能分支上(除非它是发布分支的补丁)
  • Once tested, features are merged back to master (Merge squash if you want a single commit point in master!) 测试完成后,功能将合并回主服务器(如果要在主服务器中使用单个提交点,请合并壁球!)
    • Occassionally, you might want a integration test of several features at once 有时,您可能希望一次对多个功能进行集成测试
    • Merge (squash here if you want a single commit point!) them together in order in which they occur into a combined branch off of master, branched at the commit just where the earliest feature being tested had it's branch cut from master. 将它们合并(如果需要一个提交点,请压在这里!),以便它们出现在master的组合分支中,在提交时分支,这是最早测试的功能从master切下的地方。
    • Test that combined branch then merge that into master (no squash needed as each feature is already squashed to a single commit on this combined feature branch and you don't want to loose the distinct individual feature commits) 测试组合分支,然后将其合并到主分支中(无需压缩,因为每个特征都已被压缩到该组合特征分支上的单个提交中,并且您不想丢失各个单独的特征提交)
    • Delete the combined branch 删除合并的分支
  • Delete the merged in feature branch 删除合并的功能分支
  • We test HEAD master, when a release candidate is ready we branch off a major minor numbered release branch (like release-2.4 )--this never merges back to master. 我们测试HEAD master,准备好发布候选者后,我们会分支一个主要的次要编号的发布分支(例如release-2.4 ),该分支永远不会合并回master。
  • We also tag the initial commit on branch a full version 2.4.0 我们还将分支上的初始提交标记为完整版本2.4.0
  • Any patches to a branch get a feature branch off of it, then when merged (squash if you want the patch to be a single commit point in your release branch!) back in a new tag like 2.4.1 分支的任何修补程序都会获得功能分支,然后将其合并(合并(如果您希望将修补程序作为发行分支中的单个提交点,则压扁!)),然后返回新标签(如2.4.1
  • Any fixes / patches from a realease branch that needs to get to Master or other release branches is done manually on master and each other release branch, not by merging in entire release branch. 需要进入Master或其他发行分支的,来自realease分支的任何修补程序/修补程序都是在master和其他发行分支上手动完成的,而不是合并到整个发行分支中。 Hopefully, fixes should be minor changes 希望修复应该是较小的更改

Release don't have to be at HEAD you can use any commit after the last release branch for that. 发布不必位于HEAD您可以在最后一个发布分支之后使用任何提交。

Once you've got this running smoothly, you can try to incorporating additional 'staging/develop' branches, I think you'll find limited value and much headache keeping them clean and in sync. 一旦运行顺利,就可以尝试合并其他“ staging / develop”分支,我认为您会发现价值有限,并且很难保持其清洁和同步。 I've consistently found trying to keep separate develop and master branches to be more work than value. 我一直发现尝试保持独立的开发分支和主分支是更多的工作,而不是价值。

One of the greatest benifits of this flow is how clean your history is. 此流程的最大好处之一就是您的历史记录很干净。 If you look at the network graph of it it github it's one continual chain, with only feature branches being worked on, (squashed) feature commits to master), and release branches that never merge back in. Anybody can understand clearly everything without a local git guru to interpret and without deep understanding of any idiosyncratic dev process your company may have. 如果您查看它的网络图github,它是一个连续的链,仅处理功能分支,将(压缩的)功能提交给master),然后释放从未合并的分支。任何人都可以清楚地理解所有内容,而无需本地git guru来解释您的公司,并且可能没有深入了解您的公司的任何特有开发过程。

Here are a few options: 以下是一些选择:

Git Flow (branch from develop, merge into develop) Git Flow(从开发分支到合并开发)

The idea behind git flow is that developers build and contribute to a "develop" branch and once the powers-that-be decide it's about time to do a release, you "cut" off of that branch and create a release branch to refine until it's good enough to actually be released. git flow背后的想法是,开发人员构建并为“ develop”分支做出贡献,一旦有权力决定是时候发布了版本,您就可以“切断”该分支并创建一个release分支进行优化,直到足以被实际释放。

Pros: 优点:

  • You're almost always working off of the latest version of the code. 您几乎总是在使用最新版本的代码。 If you make a change, you merge it into the develop branch right away and everyone else can build off of it. 如果您进行更改,则可以立即将其合并到developer分支中,其他所有人都可以从中进行构建。 This is convenient! 这很方便!
  • It's one of the most well known flows so a lot of people are comfortable with it 它是最著名的流程之一,因此很多人对此感到满意

Cons: 缺点:

  • The develop code can often be unstable or outright broken. 开发代码通常可能不稳定或完全损坏。 Since QA is not usually testing directly against the develop branch, issues may go unnoticed until the next release is ready to be cut. 由于质量检查通常不会直接针对开发分支进行测试,因此在准备好发布下一个版本之前,可能不会注意到问题。 In other words, quality feedback may be delayed 换句话说,质量反馈可能会延迟
  • If you are using agile, it can be difficult to keep track of where your code lives. 如果使用的是敏捷,可能很难跟踪代码的位置。 Imagine having a ticket that is assigned to a specific release and sprint. 想象一下,有一个分配给特定发布和冲刺的票证。 The code you write for this ends up being merged into develop despite what release or sprint the ticket is in. If a manager goes and moves that ticket to a different release or sprint, you may have to pull the code out of the develop branch or do some hacking to make it all work nicely. 无论票证处于哪个发行版或sprint中,为此编写的代码最终都将合并到development中。如果经理去并将该票证移至另一个发行版或sprint中,则可能必须将代码从dev分支或进行一些修改以使其全部正常运行。 This can become tedious and difficult to manage if it's happening frequently 如果这种情况经常发生,可能会变得乏味且难以管理
  • When doing hotfixes or making fixes to a release branch, you have to change your ordinary workflow and instead branch off of the release branch, master, or something entirely different. 在对发行分支进行修补或修复时,您必须更改常规工作流程,而转而脱离发行分支,母版或完全不同的分支。 This complicates the workflow and for newer developers can become very confusing 这使工作流程变得复杂,并且对于新开发人员而言可能会变得非常混乱

Branch from master; 主人的分支; merge into release branch 合并到发布分支

This is one that I think is the most straight forward but definitely has drawbacks. 我认为这是最直接的方法,但肯定有缺点。 The idea is that all features are branched off of master (which matches production at all times) with the assumption that these branches can be merged into ANY branch at ANY time. 这个想法是所有功能都从master分支(始终与生产匹配),并假设这些分支可以随时合并到ANY分支中。 When you are ready to start testing a release, you simply make a new Release_v99 branch (with an appropriate name) off of the master branch. 准备开始测试发行版时,您只需在master分支上创建一个新的Release_v99分支(具有适当的名称)即可。 You merge in the feature branches you want to be released, then test against the Release_v99 branch. 您将合并到要发布的功能分支中,然后针对Release_v99分支进行测试。

Pros: 优点:

  • Safe! 安全! Feature branches are always "safe" to be merged anywhere because they're built directly off production code. 功能分支始终是“安全的”,可以在任何地方合并,因为它们是直接在生产代码中构建的。
  • Feature branches aren't tied to a specific version of the code that isn't already deployed, so you can pretty easily move tickets around as needed without any major headaches 功能分支与尚未部署的代码的特定版本无关,因此您可以根据需要轻松移动票证,而不会造成任何麻烦
  • If your release branch turns into a disaster (due to reverts or something), it's easy to scrap it and make a new one since your feature branches can easily be merged into it again. 如果您的发布分支变成了灾难(由于还原或其他原因),则很容易将其废弃并制作新的分支,因为您的功能分支可以轻松地再次合并到其中。
  • If you want to have "long running" branches for other test environments, you can easily merge your features to these without accidentally pulling in other peoples changes 如果要在其他测试环境中使用“长期运行”的分支,则可以轻松地将功能合并到其中,而不会不小心拉扯其他人的更改

Cons: 缺点:

  • You will likely be building off of old code and therefore run into some merge conflicts. 您可能会在旧代码的基础上构建,因此会遇到一些合并冲突。 Working off of stale code can sometimes cause issues if many people are working on similar things 如果许多人正在从事类似的工作,则过时的代码有时可能会导致问题。

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

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