# synchronizing 2 heterogenous branches by cherry-pick

4 messages from 2009-07-21 to 2009-07-23. Participants: Martin Pirker, Pierre Habouzit.
Thread: https://gitlist.dev/t/20174

## Martin Pirker, 2009-07-21 12:42

Subject: synchronizing 2 heterogenous branches by cherry-pick
Message-ID: <8d53e6220907210542p4c989f3av2b57202fdd2db1f5@mail.gmail.com>
URL: https://gitlist.dev/e/8d53e6220907210542p4c989f3av2b57202fdd2db1f5%40mail.gmail.com

```
One of those weird real-world situations, advice appreciated:

Given...
one Git repository with
one branch "left" and one branch "right"
both branches have a different history (common ancestor is 0000000)
both branches have different content
_however_, at one specific commit in the "left" and "right"
branch it can be said that the content of specific
subdirectories is identical
these commits are marked with a tag "equal"

Thus, patches which only modify the identical
content can always be applied without conflicts on both branches.
I commit a new patch on "left", I can cherry-pick it to
"right" and both trees are identical again.

Issues:
Cheery-pick takes only one commit.
I have to find commits by hand.
Ideally, I want to specify equal..HEAD, if 10 commits are "left"
and "right" are 7, well, then cherry pick the last 3 from "left"
to "right".
Note that the patch content is always identical, the
commit text message (author/committer/timestamp/...) not
always
Note that ideally only one way synchronizing occurs. Bonus
points if I can add on both sides and then start magic sync...


Any good idea on how to automagically script these cherry-picking?

Martin

```

## Martin Pirker, 2009-07-23 08:41

Subject: Re: synchronizing 2 heterogenous branches by cherry-pick
Message-ID: <8d53e6220907230141l62dd1830g15ca811d5b009f2f@mail.gmail.com>
URL: https://gitlist.dev/e/8d53e6220907230141l62dd1830g15ca811d5b009f2f%40mail.gmail.com
In-Reply-To: <8d53e6220907210542p4c989f3av2b57202fdd2db1f5@mail.gmail.com>

```
I'm replying to myself.... for the archives :-)

On Tue, Jul 21, 2009 at 2:42 PM, Martin Pirker<git.collector@gmail.com> wrote:
[....]
>Any good idea on how to automagically script these cherry-picking?

tag identical content point in different branches:
 git tag tag1 commitx
 git tag tag2 commity

get list of newer commits:
 git rev-list tag1^..head1
 git rev-list tag2^..head2

compare content of commits via:
git diff --exit-code commit1 commit2

...and cherry-pick resulting list from one side to the other


Git is an amazing toolbox :-)
Martin

```

## Pierre Habouzit, 2009-07-23 08:51

Subject: Re: synchronizing 2 heterogenous branches by cherry-pick
Message-ID: <20090723085125.GL4750@laphroaig.corp>
URL: https://gitlist.dev/e/20090723085125.GL4750%40laphroaig.corp
In-Reply-To: <8d53e6220907230141l62dd1830g15ca811d5b009f2f@mail.gmail.com>

```
On Thu, Jul 23, 2009 at 10:41:37AM +0200, Martin Pirker wrote:
> I'm replying to myself.... for the archives :-)
> 
> On Tue, Jul 21, 2009 at 2:42 PM, Martin Pirker<git.collector@gmail.com> wrote:
> [....]
> >Any good idea on how to automagically script these cherry-picking?
> 
> tag identical content point in different branches:
>  git tag tag1 commitx
>  git tag tag2 commity
> 
> get list of newer commits:
>  git rev-list tag1^..head1
>  git rev-list tag2^..head2
> 
> compare content of commits via:
> git diff --exit-code commit1 commit2
> 
> ....and cherry-pick resulting list from one side to the other

Or use git cherry
-- 
Intersec <http://www.intersec.com>
Pierre Habouzit <pierre.habouzit@intersec.com>
Tél : +33 (0)1 5570 3346
Mob : +33 (0)6 1636 8131
Fax : +33 (0)1 5570 3332
37 Rue Pierre Lhomme
92400 Courbevoie

```

## Martin Pirker, 2009-07-23 09:24

Subject: Re: synchronizing 2 heterogenous branches by cherry-pick
Message-ID: <8d53e6220907230224t1ceddf31ic69bfbed84c851f@mail.gmail.com>
URL: https://gitlist.dev/e/8d53e6220907230224t1ceddf31ic69bfbed84c851f%40mail.gmail.com
In-Reply-To: <20090723085125.GL4750@laphroaig.corp>

```
On Thu, Jul 23, 2009 at 10:51 AM, Pierre Habouzit<madcoder@madism.org> wrote:
> Or use git cherry

I tried, but I was under the impression git patch-id also hashes the commit
message - or I got something else typed wrong 'cause it didn't seem to work
:-/

You are right, the solution is:
 git cherry head1 head2 tag2
 git cherry head2 head1 tag1
and cherry-pick all lines prefixed with + to the other branch.

Thanks,
Martin

```
