It is given: there are two branches, the branch prod in which that which lies on the battle server and the branch develop from which rolls out onto the test one. Of course, they are in many ways similar, but contain many fundamentally different features.
One fine day there is a need to gash a heavy feature straight from the sale. The feature is filed. The question remains - how to drag it into the development branch, so that it would not be necessary to merge all the ancestors of this feature.
See the picture:
Case A: I want to drag commits E and F without dragging commits A and B. How?
Case B: I still don’t need this (and was too lazy to draw), but it’s curious: let F be some set of consecutive commits that are not arranged in a separate branch (i.e. there is no branch containing F commits and only their ) I want to drag commits F, but I don’t want commit (s) E. How?
Case C: I want to drag the entire branch of features except one or three commits that are somewhere in the middle of the branch and are not consecutive
Case D: This is case A plus we add that the branch from the sale must be preserved.
E: is it possible to set some kind of automatic conflict resolution in the direction of (developer) / (branches with features) if they are

While I found a cherry-pick, but dragging a branch one commit at a time is still a perversion and surely there is a human way. Do I understand correctly that I need to dig somewhere in the direction of rebase?

alt text

  • Case B - you cannot make commits that will not be issued to the branch. Any commit belongs to a branch. - KoVadim
  • @KoVadim, corrected the description to make it clearer. It is clear that any sequence of commits is a branch of some tree. I mean a named branch, or are these entities not physically different? - Duck Learns to Take Cover
  • @ fori1ton, ok, thanks. Is it right to solve such a problem with the help of cherry-pick? - Duck Learns to Take Cover
  • no git just branches. Any branch has a name. In principle, you can delete a branch (commits will remain) then they will not, as it were, belong to any branch. But how to commit this anonymous branch ... And gc can easily clean up a similar "branch". But this is a separate skill in git. - KoVadim
  • one
    @Volt done - etki

3 answers 3

@Volt , git cherry-pick allows you to transfer multiple commits at once. For this, you need to set, for example, the range of commits: git cherry-pick F..E . Read more about setting commit ranges here: http://git-scm.com/docs/gitrevisions.html

    Slightly pondered himself:
    In addition to the mass cherry-peak, some of the tasks can be solved using

     git rebase -i --onto develop prod feature 

    The -i flag allows you to decide which commits to leave, which ones to drag from this set, to whom to change messages. Git will open his editor (vim by default) and offer to assign a corresponding flag to each commit from the feature branch (leave, remove, merge with the previous one) and change the messages if necessary.
    As I understand this mechanism is also used to bring the history of commits in order.

    I have not yet found a way to automatically resolve conflicts.

    • @Volt, rebase does not do one of several commits as far as I know. He simply drags the delta of everyone up to the end of the branch. - etki
    • one
      > Git will open his editor (vim) this is just fine :) vim is a separate editor, not “your own”. > I have not yet found a way to automatically resolve conflicts. it is sometimes just physically impossible. - KoVadim
    • @Fike, using rebase -i and setting the fixup and squash flags with an interactive merge, you can make several commits less with the same content. Slap them into one for example. - Duck Learns to Take Cover
    • @KoVadim, yeah, I know) Alas, I practically didn’t work with him, he is very unintuitive, therefore, is perceived as an additional obstacle ... It is clear that sometimes it is physically impossible to resolve everything directly, but I would like to learn how to automatically resolve to the specified branch . And I heard that there is such an opportunity somewhere ... - Duck Learns to Hide

    If you are working in IntelliJ IDEA, you can view logs in the console on the Version Control tab. On the logs tab, you can perform Cherry-Pick for one of the commits. Cherry-Pick is a way to pick up a single commit from another branch to the currently selected branch without affecting the rest of the commits. After that, you can make Commit and Push to a remote repository.