英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论