问题
You submit a pull request to merge Branch A
into master.
While this is pending (1 hour or so) and you want to use the pending features of branch A while you are waiting, you make Branch B
Should Branch B
be a branch off of Branch A
or should Branch B
be a branch off of master
and then merge Branch A
回答1:
Short answer: using another pullrequest can be dangerous. You still can develop your B feature then, there are 2 ways to do it:
- develop it in
A
branch and update your original pull-request, so that it contains both features, or - develop it in temporary branch (which can be anywhere you like), but after merging
A
to master rebase your work onto that merge.
Long answer:
One (but not the only) thing to beware here is the criss-cross merge. It may cause issues with conflict resolutions and sometimes even silently revert some changes. (Git claims some special care for this case, but I don't know how good it is.) It can happen even in you simple case, with the following steps:
- create branch
A
from some master commita0
- code feature
A
- merge
A
and some later master commitb0
and create branchB
there - code feature
B
- merge
A
to master during pull-request merge - now the merging
B
with master will be cris-cross one:
You could fix this exact issue. For example, you can merge master to A
, advancing it to that merge, and then start branch B
. Then subsequent merge of B
will not be criss-cross:
But there are many more possible issues which can appear. You could have several B
branches. You could have several A
branches. You could need to update A
after review, while you are already doing your B
feature. It could happen that A
is not correct at all and should be done other way, or not done at all. You might try to analyze the revision graph in each case and anticipate possible issues. But if you work in a team you probably need a simple policy which prevents possible issues. The simplest case of such policy, adopted by many teams, is that they do not use feature branches on top of each other, instead starting all of them from some master commit.
回答2:
Thought this seems to be opinion based. You could probably follow these steps :
git checkout Branch A
then create new branch
git checkout -b Branch B // creating off branch A
pull the latest master code to branch B as well to make sure you are upto date
git pull origin master //making sure master is merged to the new branch
So that a pull request from B to master
/ Branch A
would not have conflicts as well.
来源:https://stackoverflow.com/questions/36630971/correct-procedure-to-use-pending-branch-changes-in-a-new-branch