threads / discuss / 13169

Re: Q. regarding subtree merge

Subject: Re: Q. regarding subtree merge

## tl;dr

5 messages between Apr 18, 2008 and Apr 18, 2008.

replies: 4people: 3as markdown or json

Stefan Näwe· Apr 18, 2008, 09:36 UTC · lore

Q. regarding subtree merge

Hi all.

I tried the scenario described in $GIT_DIR/Documentation/howto/using-merge-subtree.txt and have some problems with it.

My setup:

I use git to track my changes in three different "project directories", lets say:

...../src_root/libfoo ...../src_root/appbar ...../bin_root/installed

All three git repositories contain a topic branch (lets say 'current-work') that I want to track.

Now I want to setup one git repository containing only the three directories 'libfoo', 'appbar', and 'installed' that others can clone easily. Reading the above howto document, I think this should be possible.

I do:
  $ mkdir super-prj 
  $ cd super-prj 
  $ git init
  $ git add remote -f libfoo ../path/to/src_root/libfoo
OK. No problem. 
The problem arises after the second step of the howto:
  $ git merge -s ours --no-commit libfoo/current-work

Now, all files of 'libfoo' are in the current directory. This is not what I want.

Could someone please tell me what I'm doing wrong?
Thanks
Stefan
Santi Béjar· Apr 18, 2008, 10:02 UTC · re: Stefan Näwe · lore

On Fri, Apr 18, 2008 at 11:36 AM, Stefan Näwe <stefan.naewe+git@gmail.com> wrote:

Show 39 quoted lines
> Hi all.
>
>  I tried the scenario described in
>  $GIT_DIR/Documentation/howto/using-merge-subtree.txt and have some problems
>  with it.
>
>  My setup:
>
>  I use git to track my changes in three different "project directories", lets
>  say:
>
>  ...../src_root/libfoo
>  ...../src_root/appbar
>  ...../bin_root/installed
>
>  All three git repositories contain a topic branch (lets say 'current-work')
>  that I want to track.
>
>  Now I want to setup one git repository containing only the three directories
>  'libfoo', 'appbar', and 'installed' that others can clone easily. Reading the
>  above howto document, I think this should be possible.
>
>  I do:
>
>   $ mkdir super-prj
>   $ cd super-prj
>   $ git init
>   $ git add remote -f libfoo ../path/to/src_root/libfoo
>
>  OK. No problem.
>
>  The problem arises after the second step of the howto:
>
>   $ git merge -s ours --no-commit libfoo/current-work
>
>  Now, all files of 'libfoo' are in the current directory. This is not what I
>  want.
>
>  Could someone please tell me what I'm doing wrong?

You are trying to merge libfoo with an empty project, so the merge just "fast-forward" to the other commit as you do not have an "ours".

Simply skip the merge step.
Santi
Santi Béjar· Apr 18, 2008, 10:09 UTC · re: Santi Béjar · lore
On Fri, Apr 18, 2008 at 12:02 PM, Santi Béjar <sbejar@gmail.com> wrote:
Show 47 quoted lines
>
> On Fri, Apr 18, 2008 at 11:36 AM, Stefan Näwe
>  <stefan.naewe+git@gmail.com> wrote:
>  > Hi all.
>  >
>  >  I tried the scenario described in
>  >  $GIT_DIR/Documentation/howto/using-merge-subtree.txt and have some problems
>  >  with it.
>  >
>  >  My setup:
>  >
>  >  I use git to track my changes in three different "project directories", lets
>  >  say:
>  >
>  >  ...../src_root/libfoo
>  >  ...../src_root/appbar
>  >  ...../bin_root/installed
>  >
>  >  All three git repositories contain a topic branch (lets say 'current-work')
>  >  that I want to track.
>  >
>  >  Now I want to setup one git repository containing only the three directories
>  >  'libfoo', 'appbar', and 'installed' that others can clone easily. Reading the
>  >  above howto document, I think this should be possible.
>  >
>  >  I do:
>  >
>  >   $ mkdir super-prj
>  >   $ cd super-prj
>  >   $ git init
>  >   $ git add remote -f libfoo ../path/to/src_root/libfoo
>  >
>  >  OK. No problem.
>  >
>  >  The problem arises after the second step of the howto:
>  >
>  >   $ git merge -s ours --no-commit libfoo/current-work
>  >
>  >  Now, all files of 'libfoo' are in the current directory. This is not what I
>  >  want.
>  >
>  >  Could someone please tell me what I'm doing wrong?
>
>  You are trying to merge libfoo with an empty project, so the merge
>  just "fast-forward" to the other commit as you do not have an "ours".
>
>  Simply skip the merge step.

Ups, I think you have to specify the parent for the new commit. Maybe change the merge step with:

$ git reset --soft libfoo/current-work
Santi
Stefan Näwe· Apr 18, 2008, 12:18 UTC · re: Santi Béjar · lore
2008/4/18, Santi Béjar <sbejar@gmail.com>:
Show 55 quoted lines
> On Fri, Apr 18, 2008 at 12:02 PM, Santi Béjar <sbejar@gmail.com> wrote:
>  >
>  > On Fri, Apr 18, 2008 at 11:36 AM, Stefan Näwe
>  >  <stefan.naewe+git@gmail.com> wrote:
>  >  > Hi all.
>  >  >
>  >  >  I tried the scenario described in
>  >  >  $GIT_DIR/Documentation/howto/using-merge-subtree.txt and have some problems
>  >  >  with it.
>  >  >
>  >  >  My setup:
>  >  >
>  >  >  I use git to track my changes in three different "project directories", lets
>  >  >  say:
>  >  >
>  >  >  ...../src_root/libfoo
>  >  >  ...../src_root/appbar
>  >  >  ...../bin_root/installed
>  >  >
>  >  >  All three git repositories contain a topic branch (lets say 'current-work')
>  >  >  that I want to track.
>  >  >
>  >  >  Now I want to setup one git repository containing only the three directories
>  >  >  'libfoo', 'appbar', and 'installed' that others can clone easily. Reading the
>  >  >  above howto document, I think this should be possible.
>  >  >
>  >  >  I do:
>  >  >
>  >  >   $ mkdir super-prj
>  >  >   $ cd super-prj
>  >  >   $ git init
>  >  >   $ git add remote -f libfoo ../path/to/src_root/libfoo
>  >  >
>  >  >  OK. No problem.
>  >  >
>  >  >  The problem arises after the second step of the howto:
>  >  >
>  >  >   $ git merge -s ours --no-commit libfoo/current-work
>  >  >
>  >  >  Now, all files of 'libfoo' are in the current directory. This is not what I
>  >  >  want.
>  >  >
>  >  >  Could someone please tell me what I'm doing wrong?
>  >
>  >  You are trying to merge libfoo with an empty project, so the merge
>  >  just "fast-forward" to the other commit as you do not have an "ours".
>  >
>  >  Simply skip the merge step.
>
>
> Ups, I think you have to specify the parent for the new commit. Maybe
>  change the merge step with:
>
>  $ git reset --soft libfoo/current-work
>

OK. Thanks. It worked without the merge. I did another test where the 'super-prj' was not empty, this time with 'git merge -s...' and that worked as well. So: If you have an empty super-prj -> drop the merge If you have a non-empty super-prj -> do the merge

But I really don't understand (yet...) why it is as it is...
Thanks
Stefan
Santi Béjar· Apr 18, 2008, 12:59 UTC · re: Stefan Näwe · lore

On Fri, Apr 18, 2008 at 2:18 PM, Stefan Näwe <stefan.naewe@googlemail.com> wrote:

> 2008/4/18, Santi Béjar <sbejar@gmail.com>:
>
[...]
Show 9 quoted lines
>  >
>  >  $ git reset --soft libfoo/current-work
>  >
>
>  OK. Thanks. It worked without the merge.
>  I did another test where the 'super-prj' was not empty, this time with
>  'git merge -s...' and
>  that worked as well. So:
>  If you have an empty super-prj    -> drop the merge
+ git reset --soft commit
If not the next "git merge -s subtree" will fail.
>  If you have a non-empty super-prj -> do the merge
>
>  But I really don't understand (yet...) why it is as it is...

Because you cannot merge an empty branch with another branch. Maybe "git merge -s ours" should fail in this case, because it does not make sense to merge an empty branch with the "ours" strategy.

Santi

← back to recent threads