# Merging repositories and their histories

8 messages from 2008-08-18 to 2008-08-22. Participants: Peter Waller, Alex Riesen, Marcus Griep.
Thread: https://gitlist.dev/t/15072

## Peter Waller, 2008-08-18 16:46

Subject: Merging repositories and their histories
Message-ID: <19035412.post@talk.nabble.com>
URL: https://gitlist.dev/e/19035412.post%40talk.nabble.com

```

I have three repositories, A, B and C. I wish to bring them together to only
one repository (.), where they are in a directory called ./Archive, so..
./Archive/{A,B,C}. Then I plan at a later date to move files arbitrarily
from ./Archive/{A/B/C}/Something and into ./Something{A/B/C}. (A lame
example, but illustrates what I want to do).

I would like ./SomethingA (etc) to have their complete histories from the
old repository. I thought I would do this with the subtree mechanism
described at
http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html,
but I have had little luck getting it to work as I desired.

Firstly, I create a new repository with git init, then I "remote add A",
"merge" and "readtree". This immediately leads to two copies of A's files,
in ./Archive/A/Files and ./Files. The files in Archive/A do not have any
history.

Then if I do this with B, the files do not appear in ./, but again they do
not have their history. I have tried using git log --follow -M, but this
does not seem to help. I have tried numerous other ways of doing this, but
none seem to work.

I thought I would get around my problems doing the merge, then moving the
files - this works for A, but when I move on to B, the files are not in ./,
so I can't move them. If I read-tree some files, git status/commit shows
them as 'new files' and does not seem to recognize them as old files with a
long history.

Any help would be appreciated on this problem.

Thanks in advance,

- Peter
-- 
View this message in context: http://www.nabble.com/Merging-repositories-and-their-histories-tp19035412p19035412.html
Sent from the git mailing list archive at Nabble.com.

```

## Alex Riesen, 2008-08-18 17:35

Subject: Re: Merging repositories and their histories
Message-ID: <20080818173511.GC6014@blimp.local>
URL: https://gitlist.dev/e/20080818173511.GC6014%40blimp.local
In-Reply-To: <19035412.post@talk.nabble.com>

```
Peter Waller, Mon, Aug 18, 2008 18:46:14 +0200:
> 
> I have three repositories, A, B and C. I wish to bring them together to only
> one repository (.), where they are in a directory called ./Archive, so..
> ./Archive/{A,B,C}. Then I plan at a later date to move files arbitrarily
> from ./Archive/{A/B/C}/Something and into ./Something{A/B/C}. (A lame
> example, but illustrates what I want to do).

If this transition is meant to be persistent (IOW, the A, B and C stop
existing as repos on their own) you can rewrite their histories to be
in the directories (with git filter-branch) and just merge them in
one. Then the histories will look like as if they have never grown
separately.

```

## Peter Waller, 2008-08-18 18:16

Subject: Re: Merging repositories and their histories
Message-ID: <d3d284ca0808181116t26e2eac3u5b8da4a8f5a91b65@mail.gmail.com>
URL: https://gitlist.dev/e/d3d284ca0808181116t26e2eac3u5b8da4a8f5a91b65%40mail.gmail.com
In-Reply-To: <20080818173511.GC6014@blimp.local>

```
I don't quite understand what you are suggesting I do.

I have looked over the filter-branch manpage.

What would I first do? Copy all three repositories to
./Archive/{A,B,C}? Then rewrite their histories?

- Peter

2008/8/18 Alex Riesen <raa.lkml@gmail.com>
>
> Peter Waller, Mon, Aug 18, 2008 18:46:14 +0200:
> >
> > I have three repositories, A, B and C. I wish to bring them together to only
> > one repository (.), where they are in a directory called ./Archive, so..
> > ./Archive/{A,B,C}. Then I plan at a later date to move files arbitrarily
> > from ./Archive/{A/B/C}/Something and into ./Something{A/B/C}. (A lame
> > example, but illustrates what I want to do).
>
> If this transition is meant to be persistent (IOW, the A, B and C stop
> existing as repos on their own) you can rewrite their histories to be
> in the directories (with git filter-branch) and just merge them in
> one. Then the histories will look like as if they have never grown
> separately.
>

```

## Alex Riesen, 2008-08-18 19:40

Subject: Re: Merging repositories and their histories
Message-ID: <20080818194021.GA3262@steel.home>
URL: https://gitlist.dev/e/20080818194021.GA3262%40steel.home
In-Reply-To: <d3d284ca0808181115j2c9ab5ecufb66780f45d28207@mail.gmail.com>

```
Peter Waller, Mon, Aug 18, 2008 20:15:52 +0200:
> 2008/8/18 Alex Riesen <raa.lkml@gmail.com>
> 
> > Peter Waller, Mon, Aug 18, 2008 18:46:14 +0200:
> > >
> > > I have three repositories, A, B and C. I wish to bring them
> > > together to only one repository (.), where they are in a
> > > directory called ./Archive, so..  ./Archive/{A,B,C}. Then I plan
> > > at a later date to move files arbitrarily from
> > > ./Archive/{A/B/C}/Something and into ./Something{A/B/C}. (A lame
> > > example, but illustrates what I want to do).
> >
> > If this transition is meant to be persistent (IOW, the A, B and C stop
> > existing as repos on their own) you can rewrite their histories to be
> > in the directories (with git filter-branch) and just merge them in
> > one. Then the histories will look like as if they have never grown
> > separately.
> >
> I don't quite understand what you are suggesting I do.
> 
> I have looked over the filter-branch manpage.
> 
> What would I first do? Copy all three repositories to ./Archive/{A,B,C}?

Fetch, actually.

    $ mkdir combined && cd combined
    $ git init
    $ git fetch ../A master:A
    $ git fetch ../B master:B
    $ git fetch ../C master:C

> Then rewrite their histories?

There is an example at the end of git-filter-branch manpage. Search
for "To move the whole tree into a subdirectory". Just use A, B and C
instead of HEAD as last argument.

Then checkout one of the new, the rewritten, branches, and merge the
two others into it:

    $ git checkout A
    $ git merge B
    $ git merge C

That's it.

```

## Peter Waller, 2008-08-18 21:25

Subject: Re: Merging repositories and their histories
Message-ID: <d3d284ca0808181425v4e0eadbcn9f00f5a15191576@mail.gmail.com>
URL: https://gitlist.dev/e/d3d284ca0808181425v4e0eadbcn9f00f5a15191576%40mail.gmail.com
In-Reply-To: <20080818194021.GA3262@steel.home>

```
Thanks, it worked.

2008/8/18 Alex Riesen <raa.lkml@gmail.com>:
> Peter Waller, Mon, Aug 18, 2008 20:15:52 +0200:
>> 2008/8/18 Alex Riesen <raa.lkml@gmail.com>
>>
>> > Peter Waller, Mon, Aug 18, 2008 18:46:14 +0200:
>> > >
>> > > I have three repositories, A, B and C. I wish to bring them
>> > > together to only one repository (.), where they are in a
>> > > directory called ./Archive, so..  ./Archive/{A,B,C}. Then I plan
>> > > at a later date to move files arbitrarily from
>> > > ./Archive/{A/B/C}/Something and into ./Something{A/B/C}. (A lame
>> > > example, but illustrates what I want to do).
>> >
>> > If this transition is meant to be persistent (IOW, the A, B and C stop
>> > existing as repos on their own) you can rewrite their histories to be
>> > in the directories (with git filter-branch) and just merge them in
>> > one. Then the histories will look like as if they have never grown
>> > separately.
>> >
>> I don't quite understand what you are suggesting I do.
>>
>> I have looked over the filter-branch manpage.
>>
>> What would I first do? Copy all three repositories to ./Archive/{A,B,C}?
>
> Fetch, actually.
>
>    $ mkdir combined && cd combined
>    $ git init
>    $ git fetch ../A master:A
>    $ git fetch ../B master:B
>    $ git fetch ../C master:C
>
>> Then rewrite their histories?
>
> There is an example at the end of git-filter-branch manpage. Search
> for "To move the whole tree into a subdirectory". Just use A, B and C
> instead of HEAD as last argument.
>
> Then checkout one of the new, the rewritten, branches, and merge the
> two others into it:
>
>    $ git checkout A
>    $ git merge B
>    $ git merge C
>
> That's it.
>

```

## Marcus Griep, 2008-08-21 21:48

Subject: Re: Merging repositories and their histories
Message-ID: <48ADE2A6.2020407@gmail.com>
URL: https://gitlist.dev/e/48ADE2A6.2020407%40gmail.com
In-Reply-To: <19035412.post@talk.nabble.com>

```
Peter Waller wrote:
> I have three repositories, A, B and C. I wish to bring them together to only
> one repository (.), where they are in a directory called ./Archive, so..
> ./Archive/{A,B,C}. Then I plan at a later date to move files arbitrarily
> from ./Archive/{A/B/C}/Something and into ./Something{A/B/C}. (A lame
> example, but illustrates what I want to do).

Peter Waller also wrote:
> Thanks, it worked.
> 
> 2008/8/18 Alex Riesen <raa.lkml@gmail.com>:
> > > Peter Waller, Mon, Aug 18, 2008 20:15:52 +0200:
> >> >> 2008/8/18 Alex Riesen <raa.lkml@gmail.com>
> >> >>
> >>> >> > Peter Waller, Mon, Aug 18, 2008 18:46:14 +0200:
> >>>> >> > >
> >>>> >> > > (The same thing as above)

Did it actually not work?

-- 
Marcus Griep
GPG Key ID: 0x5E968152
——
http://www.boohaunt.net
את.ψο´


```

## Peter Waller, 2008-08-21 21:53

Subject: Re: Merging repositories and their histories
Message-ID: <d3d284ca0808211453r2e1f1f1ak5e0a0b1ea7329a2@mail.gmail.com>
URL: https://gitlist.dev/e/d3d284ca0808211453r2e1f1f1ak5e0a0b1ea7329a2%40mail.gmail.com
In-Reply-To: <48ADE2A6.2020407@gmail.com>

```
Nabble kept telling me that my post was not submitted, which I found
very confusing, so I ended up trying to resubmit the post. Sorry for
the spam. This is now sorted.

Cheers for the keen-ness to help! :-)

- Pete

2008/8/21 Marcus Griep <neoeinstein@gmail.com>
>
> Peter Waller wrote:
> > I have three repositories, A, B and C. I wish to bring them together to only
> > one repository (.), where they are in a directory called ./Archive, so..
> > ./Archive/{A,B,C}. Then I plan at a later date to move files arbitrarily
> > from ./Archive/{A/B/C}/Something and into ./Something{A/B/C}. (A lame
> > example, but illustrates what I want to do).
>
> Peter Waller also wrote:
> > Thanks, it worked.
> >
> > 2008/8/18 Alex Riesen <raa.lkml@gmail.com>:
> > > > Peter Waller, Mon, Aug 18, 2008 20:15:52 +0200:
> > >> >> 2008/8/18 Alex Riesen <raa.lkml@gmail.com>
> > >> >>
> > >>> >> > Peter Waller, Mon, Aug 18, 2008 18:46:14 +0200:
> > >>>> >> > >
> > >>>> >> > > (The same thing as above)
>
> Did it actually not work?
>
> --
> Marcus Griep
> GPG Key ID: 0x5E968152
> ——
> http://www.boohaunt.net
> את.ψο´
>

```

## Alex Riesen, 2008-08-22 12:19

Subject: Re: Merging repositories and their histories
Message-ID: <81b0412b0808220519p7ad1c994y405ddf33ade12896@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0808220519p7ad1c994y405ddf33ade12896%40mail.gmail.com
In-Reply-To: <48ADE2A6.2020407@gmail.com>

```
2008/8/21 Marcus Griep <neoeinstein@gmail.com>:
>> 2008/8/18 Alex Riesen <raa.lkml@gmail.com>:
>> > > Peter Waller, Mon, Aug 18, 2008 20:15:52 +0200:
>> >> >> 2008/8/18 Alex Riesen <raa.lkml@gmail.com>
>> >> >>
>> >>> >> > Peter Waller, Mon, Aug 18, 2008 18:46:14 +0200:
>> >>>> >> > >
>> >>>> >> > > (The same thing as above)
>
> Did it actually not work?
>

Why not?

```
