In GitHub can I create a branch from a secondary branch and then merged it to main?

huangapple go评论61阅读模式
英文:

In GitHub can I create a branch from a secondary branch and then merged it to main?

问题

所以我有main分支。
通常我会创建一个新的分支来完成一些工作,我们称之为branch_1

现在我已经完成了在branch_1上的工作,并创建了一个PR到main分支。但在等待审核的时候,我想要做更多的工作。这个新的工作将使用branch_1的更改,但不会影响相同的文件,我们称之为branch_2

我现在已经完成了在branch_2上的工作,并创建了一个PR到main分支,但这个PR包括了来自branch_1的提交。而且这两个PR都在等待审核。
有没有办法让我的branch_2的PR不包含所有这些提交,但仍然基于branch_1工作?

英文:

So I have the main branch.
I usually open a new branch to get some work done, let call this branch_1.

I have now finished my work on branch_1 and open a PR to main. But while I wait I want to do more work. This new work will use the branch_1 changes, but it will not mess around the same files, let's call this branch_2.

I have now finished my work on branch_2 and open a PR to main, but this PR includes the commits from branch_1. And both PR are pending review.
Is there a way to have my branch_2 PR not include all these commits, but still work on top of branch_1 ?

答案1

得分: 0

如果 branch_2 依赖于 branch_1,那么你已经做得正确。如果你希望 branch_2 正常工作,你需要包括来自 branch_1 的提交。所以你应该将它们包含进去。

如果 branch_2 可以独立存在,你应该将其变基到主分支,然后提交拉取请求。在依赖于 branch_1 功能时,变基时要小心。变基将会消除 branch_1 的提交,但这也可能意味着 branch_2 现在引用了不存在的代码或使用了尚不存在的功能。

如果 branch_2 依赖于 branch_1,而你不想有一个拉取请求依赖另一个拉取请求,那么将 branch_2 合并到 branch_1 并相应更新 branch_1 的拉取请求。

英文:

If branch_2 is dependent on branch_1, then you have done things correctly. You need the commits from branch_1 if you want branch_2 to work, so you should include them.

If branch_2 can stand on it's own, you should rebase it onto main and then submit the pull request. Use caution if rebasing when dependent on branch_1 features. The rebase will eliminate the branch_1 commits, but this may also mean branch_2 is now referencing non-existent code or using features that don't yet exist.

If branch_2 is dependent on branch_1 and you don't want to have a pull request that depends on another pull request, merge branch_2 into branch_1 and update the branch_1 pull request appropriately.

huangapple
  • 本文由 发表于 2023年6月5日 17:22:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76405035.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定