git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Avery Pennarun <apenwarr@gmail.com>
To: skillzero@gmail.com
Cc: git@vger.kernel.org
Subject: Re: Subtree merging of sub-directories between repositories?
Date: Sun, 2 Aug 2009 04:30:58 -0400	[thread overview]
Message-ID: <32541b130908020130q11f1fa03yca276ab86c2ea4d5@mail.gmail.com> (raw)
In-Reply-To: <2729632a0908012337l6d84ba76o81239d324ba11cf2@mail.gmail.com>

On Sun, Aug 2, 2009 at 2:37 AM, <skillzero@gmail.com> wrote:
> Is it possible to use the subtree merge strategy to import just one
> directory from a repository into a directory of a different
> repository? The subtree merge example describes bringing in an entire
> repository as a directory, but I'm not sure how to adapt that to just
> import part of the source repository. The repositories are completely
> different, but repository A has a couple directories I want to import
> into repository B (along with the history that affected those
> directories). I may also make changes on either side and it would be
> nice to be able to re-merge in either direction.
>
> I was thinking I might need something like the git-subtree script, but
> maybe this can be done with standard git commands?

git tracks the history of the entire tree, not each subtree.  So if
you use the existing set of commit objects in A, then you'll pull in
*all* the files of A.

You have basically two choices here:

1) Merge the *entire* history of project A into project B, and during
the merge, delete the files you don't want.  (This will result in a
repo that's about the size of A+B, even if you only keep 1% of the
files, and every change to every file in A will now show up in B's
history.)  Merging future changes from A to B will be relatively easy
(although you'll get conflicts on those files you deleted), but
merging from B back to A will probably make a mess.

2) Use "git subtree split" to take the subdir of A and give it a
history of its own, then merge that history into a subdir of B (using
"git subtree add" or any other subtree merge method you want to use).
You can then git subtree split/merge back and forth between A and B in
the future to copy future changes from one to the other.

The disadvantage of #2 is that git subtree ends up creating new "fake"
commit objects for your new shared subproject.  If you merge the new
subproject back into A, you'll end up with some duplicate commit
messages (unless you use --squash).

Hope this helps.

Have fun,

Avery

  reply	other threads:[~2009-08-02  8:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-02  6:37 Subtree merging of sub-directories between repositories? skillzero
2009-08-02  8:30 ` Avery Pennarun [this message]
2009-08-02 18:05   ` skillzero
2009-08-02 18:53     ` Avery Pennarun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=32541b130908020130q11f1fa03yca276ab86c2ea4d5@mail.gmail.com \
    --to=apenwarr@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=skillzero@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).