On Tuesday, May 16, 2017 at 6:57:16 PM UTC+2, Michael Gersten wrote:
>
> If so, I think that either doing merges from master to A and B, or 
> rebasing the few commits of A and B to the tip of master as you go, is the 
> right answer.
>

I would think so as well. Alternatively, if common changes are not ready 
for master yet, additional branch should be branched off of common ancestor 
of branches A and B (commit D in the example above), holding only the 
changes that should go to both branches A and B, merging this "common" 
branch into both of them as needed:

(*1*) branch A:              E---H-----MI'-MJ'-MK'---M
                          /         /   /   /
    master:  A---B---C---D         /   /   /
                         |\       /   /   /
    common:              \ \-----I---J---K
                          \       \   \   \
    branch B:              F---G---MI"-MJ"-MK"---L


Do note that you can merge each "common" branch commit into the desired 
branch separately as soon as they`re made (as shown above), if you need 
them right away, but you can also just merge the last one, too, having the 
same effect. In terms of the final result, this is equivalent to (1):

(*2*) branch A:              E---H-------------MK'---M
                          /                 /
    master:  A---B---C---D                 /
                         |\               /
    common:              \ \-----I---J---K
                          \               \
    branch B:              F---G-----------MK"---L


In both case (1) and (2), disregarding the merge commits, branches will 
hold changes as desired:

(*3*) branch A: A, B, C, D, *E*, *H*, I, J, K, *M*
    branch B: A, B, C, D, *F*, *G*, I, J, K, *L*


On Tuesday, May 16, 2017 at 4:56:52 PM UTC+2, matevz...@borea.si wrote:
>
> At any point in the future I would like to use regular "git merge A" and 
> "git merge B" to sync and B without loosing E,H and F,G respectively.
>

`git merge` is used to join histories, simplified - incorporate _all_ new 
commits from one branch into the other. And this is not what you actually 
want, as you say you don`t want some commits from branch A inside branch B, 
and vice versa... so don`t merge them.

It makes sense to have one branch merging into the other (and not vice 
versa), where the branch we`re merging into will keep its own commits and 
get all the commits from the branch we`re merging from. The branch we`re 
merging from stays as it is, not influenced by commits existing only on the 
branch we were merging into.

But as soon as we merge the branches the other way around, too, anything 
else than branches being the same (holding the same commits), while 
possible to accomplish, may be rather confusing and greatly complicate our 
life down the road. As having branches the same is not desired in your 
case, you shouldn`t be merging them.

Regards,
Buga

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to