简体   繁体   English

如何在不合并先前分支的更改的情况下合并分支

[英]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.

相关问题 将分支中的更改合并到其他分支中,而无需合并分支 - Merge changes from branch into different branch without merging the branch 如何在git中合并2个分支,仅保留一个分支的更改 - How to merge 2 branches in git keeping the changes only from one branch 如何在不实际合并的情况下在git中合并分支? - How to merge branches in git without actually merging? 如何将更改从分支A推送到分支B而不从B分支git删除新更改(不合并) - How to push changes from branch A to branch B without removing new changes from B branch git (no merge) 如何将分支合并到具有更改或不更改的主分支? - How to merge branch to a master branch with or without changes? 如何合并来自单独分支的两个分支 - How to merge two branches from a separate branch 使所有分支合并来自devel / hotfix分支的新更改 - Make all branches merge new changes from a devel/hotfix branch 合并从 dev 分支到所有功能分支的更改 - Merge changes from dev branch to all feature branches 如何将功能分支合并到主分支中,以便也反映新的更改 - How to merge feature branches into master so that new changes also reflected 如何将工作项的更改合并到源分支以外的分支? - How to merge the changes of a Work Item to branches other than the source branch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM