简体   繁体   English

对多个开发人员使用git分支

[英]Using git branches for multiple developers

We have a project, that has multiple developers. 我们有一个有多个开发人员的项目。 Each developer has his own feature branch and once the feature is complete, it is merged with master and pushed to the remote repository. 每个开发人员都有自己的功能分支,一旦功能完成,它将与master合并并推送到远程存储库。 The problem arises: 问题出现了:

  1. If several people are working on features and they all push their changes and one of the features is buggy. 如果有几个人正在使用功能,而他们全都推动了更改,那么功能之一就是越野车。 Is there a way all of the features can be pushed to a secondary master in remote, run tests and if everything goes well, push to the master in the remote? 有没有一种方法可以将所有功能推送到远程主机中的辅助主机,运行测试,如果一切顺利,则可以推送至远程主机中的主机?

  2. Lets say all the developers are working on their feature and an emergency fix comes up, how is that best handled? 可以说所有开发人员都在开发其功能并提出紧急修复程序,如何最好地解决? It is possible that some of the developers have pushed already, but we want to push only the emergency fix? 某些开发人员可能已经推送了,但是我们只希望推送紧急修复程序吗?

Ad 1. Yes, it is possible. 广告1.是的,有可能。 Just create another branch in the remote repo as the "secondary master" if you wish so. 如果愿意,只需在远程仓库中创建另一个分支作为“二级主服务器”即可。 You can name it whatever you like, for example devel . 您可以随意命名,例如devel

Ad 2. Our team has branch called production , which should be the exact same version of what is running on production servers and from which we are deploying. 广告2。我们的团队有一个名为production的分支,该分支应该与生产服务器上正在运行以及从中进行部署的版本完全相同。 So when we need to apply hotfix, we don't have to worry about the current status of master - we just apply it to production . 因此,当我们需要应用修补程序时,我们不必担心master的当前状态-我们只需将其应用于生产

I recommend to read this, at least for inspiration: A successful Git branching model 我建议阅读这篇文章,至少是出于启发: 成功的Git分支模型

Those are all easy to do with git. 使用git可以轻松完成这些任务。 The idea would be this: 这个想法是这样的:

  • One master branch which is "stable" 一个“稳定”的master分支
  • One staging branch which tracks master and gets the feature merges first: this is where final testing is done. 跟踪母版并获取功能的一个staging分支首先合并:这是完成最终测试的地方。
  • Numerous feature branches. 众多功能分支。

If an emergency fix is done on master, this can be handled in several ways: 如果对主机完成了紧急修复,则可以通过以下几种方法进行处理:

  • cherry-pick the commit to each feature branch. 挑选每个功能分支的提交。 You can also apply the fix to some other branch and cherry-pick from there. 您还可以将修复程序应用于其他分支机构,然后从那里进行选择。 Cherry-picking is extremely localized, and can go across to and from any branch (in principle). 樱桃采摘非常本地化,可以往返于任何分支机构(原则上)。
  • merge master into the feature branch, including any "upstream" changes in one go 将母版合并到功能分支中,包括一次性进行任何“上游”更改
  • rebase the feature branch onto master. 将功能分支重新建立到master上。 This is essentially the previous item, with one major difference: a rebase will rewind and replay all the branch's commits onto the tip of master, so when the branch is merged after rebasing, it will have a very linear implementation history, and all the branch's commits come in a consecutive series. 这本质上是前一项,有一个主要区别:rebase将倒退并将所有分支的提交重播到master的顶端,因此在重新建立基础后合并该分支时,它将具有非常线性的实现历史,而所有分支的提交是连续的。

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

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