[英]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:
如果发生这种情况,您就省略了重要信息,例如:
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:
有一些基本选择:
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
orbeta
, entirely independently.功能分支完全独立地合并到EITHER
develop
或beta
。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:
有三种方法可能发生:
Feature 5 was branched out from develop after features 1-4 were merged into develop. 特征5在特征1-4合并到开发之后从开发中分支出来。
Develop was merged into feature 5 (upmerge) after features 1-4 were merged into develop. 在将特征1-4合并到开发之后,开发被合并到特征5(upmerge)中。
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. 我会按照以下步骤进行。
I will keep in mind the following things . 我会记住以下事项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.