merging to branches, doesn't matter which one you merge into?

前端 未结 2 1234
情话喂你
情话喂你 2021-02-05 06:31

git version 1.7.5.4

I have about 5 branches. All from the same initial branch.

I want to merge 2 branches together. say, branch1 and branch2. These branches have

2条回答
  •  野的像风
    2021-02-05 07:04

    Usually it does not matter if both branches are topic or feature branches.

    However, if you have an integration branch or a branch that marks what's been published, you definitely want to use the long lived integration branch as the one that's checked out and merge the other one into it.

    The reason for this is that the merge commit will mark the first parent commit as the one coming from the main branch. Your tree-ish specification for the history for that branch is easy now. To find the commit that was the 4th last in this branch, you simply

    git show head~4
    

    If you merged from the other branch somewhere in between, you would have to explicitly switch to the second commit wherever the merge was done the other way:

    git show head^^2^^
    

    This can cause problems with major branches for another reason; merging them into topic or feature branches is referred to as "back merging" and is not a good idea. I recall Linus Torvalds blowing his top when contributors did that. It would not allow him to cleanly separate what features he wanted to merge for a major revision as the feature branches would bring in an old test merge that included things he does not want anymore.

    So in the end, if one branch is more significant and is more than just a feature, check it out and merge from there. You'll be able to keep it's history viewed easily as you know that it's first parent is always where that branch was before. If you don't, you'll have to rely on reading the merge commit messages and it's just not as fun. :)

    I've written an article about BpF which shows a rigorous method of keeping branches organized: http://dymitruk.com/blog/2012/02/05/branch-per-feature/

提交回复
热议问题