how to use git merge -s subtree?

7 messages, 3 authors, 2016-06-15 · open the first message on its own page

how to use git merge -s subtree?

From: Miklos Vajna <hidden>
Date: 2016-06-15 22:44:02

hi,

i recently noticed that the subtree merge strategy is missing from
merge-strategies.txt an i tried to first figure out how it works. i got
it to work, but i'm not 100% sure about i'm using it the way i'm
supposed to.

here is what i do:

1) git remote add B /path/to/B.git
2) git fetch
3) mkdir B
4) touch B/.gitignore
5) git add B/.gitignore
6) git commit -m "add empty B directory"
7) git merge -s subtree B/master

and yes, it works pretty well, but is this the right way? or is it
possible to somehow avoid steps 3..6?

thanks,
- VMiklos

Re: how to use git merge -s subtree?

From: Sean <hidden>
Date: 2016-06-15 22:44:02

On Sun, 6 Jan 2008 00:00:04 +0100
Miklos Vajna [off-list ref] wrote:
i recently noticed that the subtree merge strategy is missing from
merge-strategies.txt an i tried to first figure out how it works. i got
it to work, but i'm not 100% sure about i'm using it the way i'm
supposed to.

here is what i do:

1) git remote add B /path/to/B.git
2) git fetch
3) mkdir B
4) touch B/.gitignore
5) git add B/.gitignore
6) git commit -m "add empty B directory"
7) git merge -s subtree B/master

and yes, it works pretty well, but is this the right way? or is it
possible to somehow avoid steps 3..6?
Hi Miklos,

Here's another way that is perhaps a little cleaner:

$ git remote add -f B /path/to/B
$ git merge -s ours --no-commit B/master
$ git read-tree --prefix=sub/ -u B/master 
$ git commit -m "subtree merged B"

The first line creates and fetches the remote.  The second line initiates a merge, but
stops before committing it.  The third line reads B/master into the subdirectory "sub",
at which point all that remains is committing the completed merge.

HTH,
Sean
 

Re: how to use git merge -s subtree?

From: David Soria Parra <hidden>
Date: 2016-06-15 22:44:02

As said in IRC, subtree is not made for that as far is a understand.

Quite frankly the given workflow doesnot work for me as subtree imports
the things into some directory that it was not supposed to merge it into
(x/z/ instead of B).

                              dsp

Re: how to use git merge -s subtree?

From: David Soria Parra <hidden>
Date: 2016-06-15 22:44:02

Hi Miklos,

Here's another way that is perhaps a little cleaner:

$ git remote add -f B /path/to/B
$ git merge -s ours --no-commit B/master
$ git read-tree --prefix=sub/ -u B/master 
$ git commit -m "subtree merged B"
hi sean,

that works perfectly but it doesn't preserve the history, does it?

                    dsp

Re: how to use git merge -s subtree?

From: Sean <hidden>
Date: 2016-06-15 22:44:02

On Sun, 06 Jan 2008 02:22:47 +0100
David Soria Parra [off-list ref] wrote:
quoted
Here's another way that is perhaps a little cleaner:

$ git remote add -f B /path/to/B
$ git merge -s ours --no-commit B/master
$ git read-tree --prefix=sub/ -u B/master 
$ git commit -m "subtree merged B"
that works perfectly but it doesn't preserve the history, does it?
David,

Yes, the reason to start with the "--no-commit" merge is so that the history
is properly connected once you do the final commit step.  However, I should
have noted in my original message that none of the steps actually use the
subtree merge.  Instead they simply prepare a repository such that
future merging can be done with:

   $ git merge -s subtree B/master.

Cheers,
Sean

Re: how to use git merge -s subtree?

From: David Soria Parra <hidden>
Date: 2016-06-15 22:44:02

Sean wrote:
David,

Yes, the reason to start with the "--no-commit" merge is so that the history
is properly connected once you do the final commit step.  However, I should
have noted in my original message that none of the steps actually use the
subtree merge.  Instead they simply prepare a repository such that
future merging can be done with:

   $ git merge -s subtree B/master.

Cheers,
Sean
Well yes the history is preserved, but it's not connected to the
subdirectory. So you cannot do git-log B/foo.c as git doesnot know where
to search it as it thinks
it is in /foo.c not in B/foo.c

Cheers

Re: how to use git merge -s subtree?

From: Miklos Vajna <hidden>
Date: 2016-06-15 22:44:02

On Sat, Jan 05, 2008 at 08:17:40PM -0500, Sean [off-list ref] wrote:
Here's another way that is perhaps a little cleaner:

$ git remote add -f B /path/to/B
$ git merge -s ours --no-commit B/master
$ git read-tree --prefix=sub/ -u B/master 
$ git commit -m "subtree merged B"

The first line creates and fetches the remote.  The second line initiates a merge, but
stops before committing it.  The third line reads B/master into the subdirectory "sub",
at which point all that remains is committing the completed merge.
great, thanks. that's more simple than mine, and this is necessary for
the first commit only. the rest (i hope i'm right) can be done using
just by

$ git fetch
$ git merge -s subtree B/master

do you mind if i send a patch to add this to Documentation/howto? i
don't think it's trivial :)

thanks,
- VMiklos
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help