[英]How to merge a branch without also merging changes from previous branches
I am kind of new to git and have a question regarding branching and merging those branches.我对 git 有点陌生,并且对分支和合并这些分支有疑问。
Let's say in my project repo I have 3 "main" branches: Alpha, Beta, Production.假设在我的项目仓库中,我有 3 个“主要”分支:Alpha、Beta、Production。
Here is a scenario I am facing:这是我面临的一个场景:
I currently work on the Alpha branch on my local machine.我目前在本地机器上的 Alpha 分支上工作。 I create a new branch from Alpha, let's call it
feature/newFeature
.我从 Alpha 创建了一个新分支,我们称之为
feature/newFeature
。 After creating the feature I commit and push the changes and then I merge feature/newFeature
into the Alpha branch for QA to test.创建功能后,我提交并推送更改,然后将
feature/newFeature
合并到 Alpha 分支中以供 QA 测试。 If QA approves, then it gets merged into Beta, then Production, etc.如果 QA 批准,则将其合并到 Beta,然后是 Production 等。
Now, after feature/newFeature
has been merged into Alpha (and not any other branch yet) I create another branch from Alpha, call it fix/hotfix
.现在,在
feature/newFeature
被合并到 Alpha (而不是任何其他分支)之后,我从 Alpha 创建了另一个分支,称之为fix/hotfix
。 After fixing what needs to be fixed I merge this branch into Alpha as well.在修复了需要修复的内容后,我也将此分支合并到 Alpha 中。
But (and here is the problem I am facing), let's say that fix/hotfix
has been tested and is working and can be merged into Beta, but feature/newFeature
is still being tested on Alpha.但是(这是我面临的问题),假设
fix/hotfix
已经过测试并且正在运行并且可以合并到 Beta 中,但feature/newFeature
功能仍在 Alpha 上进行测试。 If I try to merge the fix/hotfix
branch into Beta, it will also merge changes from the feature/newFeature
branch into Beta (which I obviously don't want because it is still being tested).如果我尝试将
fix/hotfix
分支合并到 Beta 中,它也会将feature/newFeature
分支中的更改合并到 Beta 中(我显然不想要,因为它仍在测试中)。
I understand why this happens, because when I merge feature/newFeature
into Alpha and then create the fix/hotfix
branch from Alpha after that merge, the fix/hotfix
branch also contains the changes from the feature/newFeature
branch.我理解为什么会发生这种情况,因为当我将
feature/newFeature
合并到 Alpha 中,然后在合并后从 Alpha 创建fix/hotfix
分支时, fix/hotfix
分支还包含来自feature/newFeature
分支的更改。
My question is: Is there any way to do it in such a way that I can merge the fix/hotfix
branch into Beta without it also merging the previous branches/changes that shouldn't be merged yet?我的问题是:有没有什么方法可以将
fix/hotfix
分支合并到 Beta 中,而不会合并以前不应该合并的分支/更改?
You can always copy fix/hotfix branch and rebase it onto beta您始终可以复制修复/修补程序分支并将其重新设置为 beta
git checkout fix/hotfix
git checkout -b fix/hotfix-copy
git rebase beta
That should leave you with the hotfix changes on beta branch.这应该让您了解 beta 分支上的修补程序更改。 Then just merge the hotfix
然后只需合并修补程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.