简体   繁体   English

在变基到 Git 中的 Master 之前与另一个功能分支合并

[英]Merging with another feature branch before rebasing to Master in Git

So I'm trying to understand how Git handles certain processes and what are some already used practices.所以我试图了解 Git 如何处理某些流程以及一些已经使用的实践。

Let's say we have a Git repository with a branch called master .假设我们有一个 Git 存储库,其中有一个名为master的分支。 We also have two branches that are created simultaneously from master .我们还有两个从master同时创建的分支。 We'll call them branch_one and branch_two .我们称它们为branch_onebranch_two

branch_one already has work completed for a specific feature. branch_one已经完成了特定功能的工作。 I am currently developing on branch_two .我目前正在开发branch_two For the sake of this conversation, let's assume that I can't merge branch_one to master because it's pending approval from other developers.为了这次对话,让我们假设我无法将branch_one合并到master ,因为它正在等待其他开发人员的批准。

Here's the issue:这是问题所在:

I need all of the work from branch_one in order to continue work on branch_two .我需要branch_one的所有工作才能继续branch_two的工作。

Here is my current flow:这是我目前的流程:

1) merge branch_one into branch_two . 1)合并branch_onebranch_two
2) work on branch_two . 2) 处理branch_two
3) rebase branch_two with master before submitting a pull request. 3) 在提交拉取请求之前将branch_twomaster变基。

Uh-oh.呃哦。 The rebase has conflicts on 30+ patches. rebase 在 30 多个补丁上有冲突。 I assume this is because the merge (step 1) changes the head of branch_two .我认为这是因为合并(第 1 步)更改了branch_two的头部。 I may be assuming incorrectly.我可能假设不正确。

Obviously I would like to avoid a massive conflict resolution step in my version control process.显然,我想在我的版本控制过程中避免大量的冲突解决步骤。

So my questions:所以我的问题:

Is there a better way to handle this type of process, where a feature branch requires changes from another feature branch, that doesn't include massive conflicts?有没有更好的方法来处理这种类型的过程,其中一个功能分支需要来自另一个功能分支的更改,不包含大量冲突?

You need an integration branch, made from master HEAD:您需要一个由主 HEAD 制作的集成分支:

  • merge branch1 in integration在集成中合并 branch1
  • rebase branch2 on top of integration.在集成之上重新设置 branch2。

If branch1 needs additional work in the context of its validation, merge the new branch1 commits in integration again.如果 branch1 需要在其验证上下文中进行额外的工作,请再次合并新的 branch1 提交以进行集成。
At some point, branch1 will be merge into master.在某个时候,branch1 将合并到 master 中。

Then, whenever you want to validate branch2, rebase it first on top of the updated integration branch.然后,每当您想要验证 branch2 时,首先将其重新设置在更新的集成分支之上。 Then merge it to integration (using --no-ff : no fast-forward merge).然后将其合并到集成(使用--no-ff :无快进合并)。

Finally, merge branch2 to master when ready.最后,准备好后将 branch2 合并到 master。 No conflict there.那里没有冲突。

For more on this workflow, see gitworkflow (far better than Gitflow )有关此工作流程的更多信息,请参阅 gitworkflow (比Gitflow 好得多

You are running into a common pitfall in GIT.您遇到了 GIT 中的一个常见陷阱。 The solution is always, think ahead.解决方案总是,提前想好。 In your scenario, knowing whether or not you'll need a feature from one branch ahead of time will give you the ability to branch in a way that avoids this issue:在您的场景中,提前知道您是否需要一个分支的功能将使您能够以一种避免此问题的方式进行分支:

create a branch off of master that will be an epic-branch从 master 创建一个分支,这将是一个史诗分支

git checkout -b epicBranch

create both branch_one & branch_two off of epicBranchepicBranch创建branch_onebranch_two

git checkout -b branch_one git checkout -b branch_two git checkout -b branch_one git checkout -b branch_two

Once you need a feature from branch_one you PR and merge branch_one into epicBranch then merge epicBranch into branch_two一旦您需要来自branch_one的功能,您就可以 PR 并将branch_one合并到epicBranch ,然后将epicBranch合并到branch_two

git checkout branch_two
git merge epicBranch

Now you have the change from branch_one in branch_two without the overhead of closing branches.现在您可以从branch_onebranch_two进行更改,而无需关闭分支的开销。

You will have the commit history and shouldn't run into any issues when merge or rebasing.您将拥有提交历史记录,并且在合并或变基时不应遇到任何问题。

You can also save a lot of headache by cherry picking your needed feature commit into a branch of its own that can be shared between branches.您还可以通过将需要的功能提交到一个可以在分支之间共享的自己的分支中来避免很多麻烦。

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

相关问题 Git:是否将master合并到master上的功能分支和REBASING功能分支上? - Git: Are MERGING master into feature branch and REBASING feature branch on master equivalent? Git:在特征分支中压缩或重新建立基础时,为什么需要将其与另一个分支(例如master)进行比较? - Git: When squashing or rebasing in a feature branch, why do you need to compare it to another branch like master? 使用基于功能分支的 rebase 提交消息修改,然后合并到 master - Commit message amend using rebasing on feature branch and then merging into master 将 master 重新定位到功能分支上? - Rebasing master onto feature branch? git 在使用主分支重新设置功能分支之后拉功能分支将恢复重新设置更改 - git pull feature branch just after rebasing feature branch with master branch will revert rebase changes Git - 撤消将主分支合并到另一个分支 - Git - Undo merging master branch into another branch 基于另一个功能分支合并功能分支,回到 master - Merging feature branch based on another feature branch, back to master Git:将大型主分支与功能分支合并 - Git: Merging very large master branch with a feature branch Git Merging Branch成Master - Git Merging Branch Into Master Git:在合并到master之前从master转移到topic分支? - Git: pull from master to topic branch before merging into master?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM