简体   繁体   English

问题将Git Feature分支合并到“Beta”分支(在它已经合并到“Develop”分支之后)

[英]Issue merging Git Feature branch into “Beta” branch (after it has already been merged to “Develop” branch)

We have a standard web project and maintain 3 core branches for this project: Master, Beta, and Develop. 我们有一个标准的Web项目,并为该项目维护3个核心分支:Master,Beta和Develop。 Here is a summary of the process/workflow that we use: 以下是我们使用的流程/工作流程的摘要:

(1) A new feature/update is requested so we create a new Feature branch. (1)请求新功能/更新,以便我们创建新的功能分支。

(2) A commit is made for the new Feature branch and the Feature branch is merged into the 'Develop' branch; (2)为新功能分支进行提交,并将功能分支合并到“开发”分支中; the 'Develop' branch is then published to a testing environment to be tested. 然后将“开发”分支发布到要测试的测试环境。

(3) Once the new feature is tested/approved, a new pull request is made in the same Feature branch; (3)测试/批准新功能后,在同一功能分支中进行新的拉取请求; this new pull request is meant to be merged into the 'Beta' branch. 这个新的pull请求被合并到'Beta'分支中。

The 'Beta' branch has all of our "ready-to-go-live" features: in fact, we publish the 'Beta' branch directly to the production environment and when that is ready we immediately merge the 'Beta' branch to the 'Master' branch....by doing this, the 'Master' branch is always a copy of the code that is on the production environment. 'Beta'分支具有我们所有的“准备就绪”功能:事实上,我们将'Beta'分支直接发布到生产环境,当它准备就绪时,我们立即将'Beta'分支合并到'Master'分支......通过这样做,'Master'分支始终是生产环境中代码的副本。

The problem: in step 3 above, when we try to merge the new Feature branch into the 'Beta' branch, the pull request includes ALL new commits that have been merged into the 'Develop' branch. 问题:在上面的步骤3中,当我们尝试将新的Feature分支合并到'Beta'分支时,pull请求包括已合并到'Develop'分支中的所有新提交。

Example: 5 feature branches are individually merged to the 'Develop' branch (branches are labeled 1, 2, 3, 4, and 5). 示例:5个要素分支分别合并到“Develop”分支(分支标记为1,2,3,4和5)。 All 5 are tested, but there are bugs with the first 4. So branch "5" is approved and we try to create a pull request for that Feature branch and merge it to 'Beta'....but when we do that, the pull request includes all 5 feature branches....not just the commit for branch "5". 所有5个都经过了测试,但是前面有4个错误。所以分支“5”被批准,我们尝试为该功能分支创建拉取请求并将其合并为“Beta”....但是当我们这样做时, pull请求包括所有5个功能分支....而不仅仅是分支“5”的提交。

We MUST be doing something wrong! 我们必须做错事! What can we do to fix our process/workflow? 我们可以做些什么来修复我们的流程/工作流程?

(3) Once the new feature is tested/approved, a new pull request is made in the same Feature branch; (3)测试/批准新功能后,在同一功能分支中进行新的拉取请求; this new pull request is meant to be merged into the 'Beta' branch. 这个新的pull请求被合并到'Beta'分支中。

The 'Beta' branch has all of our "ready-to-go-live" features: in fact, we publish the 'Beta' branch directly to the production environment and when that is ready we immediately merge the 'Beta' branch to the 'Master' branch....by doing this, the 'Master' branch is always a copy of the code that is on the production environment. 'Beta'分支具有我们所有的“准备就绪”功能:事实上,我们将'Beta'分支直接发布到生产环境,当它准备就绪时,我们立即将'Beta'分支合并到'Master'分支......通过这样做,'Master'分支始终是生产环境中代码的副本。

The problem: in step 3 above, when we try to merge the new Feature branch into the 'Beta' branch, the pull request includes ALL new commits that have been merged into the 'Develop' branch. 问题:在上面的步骤3中,当我们尝试将新的Feature分支合并到'Beta'分支时,pull请求包括已合并到'Develop'分支中的所有新提交。

No, that does not make sense. 不,这没有意义。 If that happens you have omitted important information such as: 如果发生这种情况,您就省略了重要信息,例如:

  • Each new feature branch is branched off of another branch. 每个新功能分支都从另一个分支分支出来。 Which one, development? 哪一个,发展? Then it is clear that whatever development commits are in the history of a newly created feature, will also be merged into the beta branch. 然后很明显,无论开发提交是否在新创建的功能的历史中,也将合并到beta分支中。 Git history is a directed acyclic graph, each commit pointing to one (normal commit) or multiple (merge commit) parent commits. Git历史是一个有向无环图,每个提交指向一个(正常提交)或多个(合并提交)父提交。
  • In order to make features merge cleanly into develop, maybe the feature branches are rebased onto development regularly or maybe the feature branches get refreshed by merging in the latest develop, both of which makes much sense and I advocate it. 为了使功能完全合并到开发中,可能会将功能分支定期重新定位到开发中,或者可能通过合并最新的开发来更新功能分支,这两者都很有意义,我提倡它。 But in this case also their history contains all the history of develop at the time of merging/rebasing. 但在这种情况下,他们的历史也包含了合并/变基时的所有发展历史。

In each of these cases your workflow is fundamentally broken and cannot work with regard to your idea of a beta branch. 在每种情况下,您的工作流程都会从根本上被打破, 并且无法满足您对beta分支的看法。 So if you want to avoid cherry-picking (bad! bad! bad!) how can you achieve what you want to do? 因此,如果你想避免挑选(糟糕!糟糕!糟糕!)你怎么能实现你想做的事情? There are some basic options: 有一些基本选择:

  1. Feature toggles: ugly. 功能切换:丑陋。 I would stay away from it whenever possible. 我会尽可能远离它。 The best way to inactivate a feature in any branch is not having the corresponding commits on that branch in the first place. 在任何分支中停用功能的最佳方法是首先在该分支上没有相应的提交。
  2. Work cleanly: good. 干净利落地工作:好。 Refrain from merging back untested/unaccepted features to develop. 避免合并未经测试/未接受的功能以进行开发。 Only merge them when they are done (as in "definition of done") and accepted by the client. 只有在完成后才会合并(如“完成定义”)并由客户接受。 Make sure you set up an environment enabling your clients to directly test on feature branches instead of mashing it all up onto a beta branch. 确保您设置了一个环境,使您的客户可以直接在功能分支上进行测试,而不是将其全部压缩到测试版分支上。 This way whatever gets on development is inherently ready for production and you do not need the beta branch anymore. 这样开发的任何内容都固有地为生产做好准备,您不再需要beta分支。 Unfinished work is never to be merged into a higher-level branch. 未完成的工作永远不会被合并到更高级别的分支。 This is what GitFlow is all about and it works. 这就是GitFlow的全部内容,它的工作原理。 Even if you do not use GitFlow in its full glory but just master, develop and feature branches, the validity of my statements holds. 即使你没有完全使用GitFlow,但只是掌握,开发和功能分支,我的陈述的有效性仍然存在。 I have worked like this in many projects and it works beautifully. 我在很多项目中都是这样工作的,而且效果很好。 Besides, if you think you need another branch to integrate features onto for future releases, create a new "next_release" or "future" branch for them and merge them to that branch, not onto develop. 此外,如果您认为需要另一个分支来集成功能以用于将来的版本,请为它们创建一个新的“next_release”或“future”分支,并将它们合并到该分支,而不是开发。 Then regularly refresh future from develop because you also want your features from the current release in the future release, but not vice versa. 然后定期从开发中刷新未来,因为您还希望在将来的版本中使用当前版本中的功能,但反之亦然。 I hardly believe that this additional step will be necessary though. 我不相信这个额外的步骤是必要的。

That's the way git works. 这就是git的工作方式。 You'll need to create separate branches for each feature. 您需要为每个功能创建单独的分支。

Once you merge a branch with another, the merging branch commits get commited on the home branch. 分支与另一个分支合并后 ,合并分支提交将在主分支上进行提交。

What you probably want to be doing is not even work on the development branch for development, but rather branch out of it for each feature (serialize the features, of course) which are then separately checked for bugs before merging packages of many feature branches into the development branch. 您可能想要做的甚至不是在开发分支上进行开发,而是为每个功能分支(当然是序列化功能),然后在将许多功能分支的包合并到​​之前单独检查错误。开发部门。

To get rid of bugs that got into the development branch anyway you will need to get the code working on the feature branch and then merge that OR revert the changes by reverting the feature branch using git revert and then merging the branch again (effectively reverting only the commits that it introduced to the development branch . 要摆脱进入开发分支的错误,你需要让代码在特征分支上工作然后合并,或者通过使用git revert 特征分支然后再次合并分支git revert更改(仅有效地恢复分支)它引入开发分支的提交。

Reverting on the development branch (or any of the bigger branches in your hierarchy) is generally ill advised in the industry, except when you merge just a single feature... as different commits can establish dependencies between themselves and reverting can cause more harm than it solves. 恢复开发分支(或层次结构中的任何更大的分支)在业界通常是不明智的,除非您只合并一个功能...因为不同的提交可以在它们之间建立依赖关系并且恢复可能会造成比它解决了。

To get a better hang on reverting read this guide by atlassian or the available documentation . 为了更好地坚持恢复,请阅读atlassian可用文档阅读本指南

You're correct, our workflow differs from the traditional GitFlow. 你是对的,我们的工作流程与传统的GitFlow不同。 Feature branches are merged into EITHER develop or beta , entirely independently. 功能分支完全独立地合并到EITHER developbeta

Once the new feature is tested/approved, a new pull request is made in the same Feature branch 测试/批准新功能后,将在同一功能分支中生成新的拉取请求

        f2--f2--f2   (f2)
       /          \
d--d--d--D1-------D2 (develop)
\       /
 f1---f1

a bunch of unwanted/unrelated feature branch commits are merged into "beta" as well 一堆不需要/不相关的功能分支提交也被合并到“beta”中

Strange: that would be as if f2 was on the D2 merge commit (which has f2 but also f1). 奇怪的是:这就好像f2在D2合并提交(它有f2但也是f1)上。

For testing, could you try in command-line to cherry-pick the exact commits you want , then merge them with --squash . 为了测试,你可以尝试在命令行中挑选你想要的确切提交 ,然后将它们与--squash合并

git checkout -b tmp develop
git cherry-pick  $(git merge-base develop f2) f2
git checkout beta
git merge --squash tmp

That way, you can validate you only get the exact f2 merged branch you want in beta, and not all the other features. 这样,您可以验证您只获得测试版所需的f2合并分支,而不是所有其他功能。
Once that is validated, we can work on doing the same from a GUI (like for instance SourceTree) 一旦验证,我们就可以从GUI(例如SourceTree)做同样的事情。

You say that merging feature 5 into beta will bring features 1-4 into beta as well. 你说将功能5合并到测试版中也会将功能1-4带入测试阶段。 If so, the commits for features 1-4 are definitely in the feature 5 branch. 如果是这样,功能1-4的提交肯定在功能5分支中。 There are 3 ways that could happen: 有三种方法可能发生:

  1. Feature 5 was branched out from develop after features 1-4 were merged into develop. 特征5在特征1-4合并到开发之后从开发中分支出来。

  2. Develop was merged into feature 5 (upmerge) after features 1-4 were merged into develop. 在将特征1-4合并到开发之后,开发被合并到特征5(upmerge)中。

  3. Features 1-4 were merged directly into feature 5. 功能1-4直接合并到功能5中。

Beware that a branch contains not just the commits made directly to the branch, but also all commits from the beginning of the repo up to the branching point, and any commits in branches merged into the branch. 请注意,分支不仅包含直接提交给分支的提交,还包括从repo开始到分支点的所有提交,以及分支中的任何提交都合并到分支中。

BTW, the 3 points above hold even if you change 'merge' to 'rebase', or 'develop' to any other branch. 顺便说一下,即使你将'merge'改为'rebase',或者'发展'到任何其他分支,上述3分仍然保持不变。

I would be doing the follow steps. 我会按照以下步骤进行。

  • Feature branches created from develop. 从开发创建的功能分支。
  • Once feature are done merge them to develop branch. 完成功能后,将它们合并为开发分支。
  • When time for testing comes I will create a test branch and do the tests there.I will fix any bug which comes in testing there itself. 当测试时间到来时,我将创建一个测试分支并在那里进行测试。我将修复测试中出现的任何错误。
  • Once my test are all successful I merge the branch to both master and develop. 一旦我的测试全部成功,我将分支合并到master和develop。
  • I would then release my code from master to Beta environment. 然后我会将我的代码从master环境发布到Beta环境。

I will keep in mind the following things . 我会记住以下事项。

  • If a feature is not needed for particular release I would not merge that feature to develo branch. 如果特定版本不需要某个功能,我不会将该功能合并到develop分支。
  • If I could not solve any bugs while testing I would not be releasing that code,hence as in the question I would have solved all the bugs and would be releasing the whole code. 如果我在测试时无法解决任何错误,我将不会发布该代码,因此在问题中我会解决所有错误并将释放整个代码。

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

相关问题 检查develop分支是否已合并到功能分支中? - Checking if develop branch has been merged into feature branch? GIT merge develop into feature branch -- 同一个分支被合并和恢复后 - GIT merge develop into feature branch -- after the same branch was merged and reverted 在Git中将开发分支与本地特征分支合并 - Merging develop branch with local feature branch in Git 在 git 将一个分支合并到另一个已经与另一个分支合并的分支时遇到问题...致命错误或 MERGE_MSG - Having troubl in git merging a branch into another branch that has already been merged with another branch... fatal error or MERGE_MSG 在功能分支直接合并到发布后面临合并开发到发布分支的问题 - Facing issues merging develop to release branch after feature branch got merged to release directly Git 将开发分支上的功能合并到另一个已经存在的开发分支 - Git merge feature on develop branch to another already existing develop branch 已经与master合并的分支中的错误如何解决? - How to fix a bug in a branch after it has already been merged with master? 重新设置已经合并的分支 - Rebase a branch that has already been merged 分支合并到 master 后的 git rebase - git rebase after branch has been merged into master 如何判断壁球之后git分支是否已完全合并 - How to tell if git branch has been fully merged after squash
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM