Does Git merge have to merge branches? Can I merge two commits?
学习ing
学习ing 2017-06-17 09:15:31
0
2
1241

Git merge merge operation, is it necessary to merge the tip of branch? Can any two commits be merged?
For example, there is branch hotfix and branch master, the structure is as follows:

/A+--+B+----+C hotfix /

init---->D --->E --->F ---->G master

Question 1:
I want to merge a commit in the middle of the thotfix branch, such as B, to the current branch master.
May I?
Because judging from the parameter explanation of the command, commit can be used instead of the branch name branchName.

Question 2:
If there is still a branch topic (not shown in the picture), and the current branch is master, I hope to merge the hotfix and topic branches, but not merge them into the current branch master, and do not switch branches at the same time. Requirements Is it possible to keep the current branch still master?
Because judging from the parameters of the command, multiple commits can be accepted. The manual says that the merger of multiple commits constitutes an octopus merge. I was wondering whether the merger of multiple commits must be merged into the current branch. So there is this problem.

学习ing
学习ing

reply all (2)
左手右手慢动作

Use cherry-pick to pick the submissions you want

    阿神

    First of all, there seems to be something wrong with your picture. You can’t tell where the two branches are separated. You should use thegit cherry-pickcommand instead ofmerge. I can only guess, is that so?

    A - B - C hotfix / init - D - E - F - G master

    The following answers are all based on this guess. If it's different from yours, please comment.

    Question 1: To put it simply, it is best to usecherry-pick.
    First of all, you need to know thatgit merge andgit cherry-pick are different. . If you were to usegit merge Bhere, you would get something like this:

    A - B - C hotfix / \ init-D-E-F-G-G' master

    But if you weregit cherry-pick B, you would get this result:

    A - B - C hotfix / init - D - E - F - G - B' master

    mergehas its advantages, because every timemergeactually creates a new "merge commit" and "preserves history", so it is a "non-destructive" process. Of course,cherry-pickalso has its drawbacks, the first being the creation of a new hash, which may lead to confusion in multi-person collaboration. For example, if someone has added HJKL after G, then at least he needs torebase. In addition, this B' will not retain its own history likemerge. So, to be precise, this B' is more like a patch. (Please refer togit format-patchhttps://git-scm.com/docs/git-...

    I personally prefer commands likecherry-pickandrebase, but I don’t likemergevery much, mainly because the history line is much simpler. Although these two commands are slightly more destructive thanmerge, it is good to be a little familiar with git and know what each step is doing and what impact it may have.


    Question 2:
    It feels like it’s not possible.mergedoes not have parameters like--ontolikerebase. It’s better to switch over andmerge.

    When you mentioned the octopus merger later, did you mean--strategy=octopus? Not sure what this strategy has to do with what you're asking about. . Because the default strategy ofmergefor multiplebranchis octopus. . No need to set it up specifically. . . By the way, for a single HEAD'smerge, the default strategy is recursive.

    For the merging of multiple commits you mentioned, please describe your needs in detail. Or draw a picture to supplement it

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!