Git development
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Andrew Arnott <andrewarnott@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Merging two projects
Date: Mon, 3 Nov 2008 23:56:44 -0500	[thread overview]
Message-ID: <20081104045644.GC31276@coredump.intra.peff.net> (raw)
In-Reply-To: <216e54900811031933n346e8c68se9226e79366c3eb6@mail.gmail.com>

On Mon, Nov 03, 2008 at 07:33:21PM -0800, Andrew Arnott wrote:

> I have two projects, both with histories, that I want to merge into
> just one library.  I'd like to preserve both histories, perhaps as if
> there were two branches being merged into one.  (Although each project
> has its own branches that will make the history interesting).
> 
> Is there a standard way to do this?

You have two options:

 - just merge the history as if they were two branches:

     # make a new combined repo
     mkdir merged && cd merged && git init

     # pull in each library
     for lib in lib1 lib2; do
       git fetch /path/to/$lib master:$lib
       git checkout $lib
       # do any pre-merging fixups
       mkdir $lib
       mv * $lib
       git add -u
       git add $lib
       git commit -m "move files into $lib in preparation for project merge"
     done

     # and then merge; order isn't really important
     git checkout lib1
     git merge lib2

   This method is nice because it preserves the original histories, and
   you can still merge from the original projects (if people are still
   working on them as individual projects).

   Note that this is basically what the subtree merge strategy does, so
   you could also use that. I showed all the steps here to give a sense
   of what is going on, and because you might want to do additional
   fixups besides moving files into the subtree.

 - The other alternative is rewriting the history. The advantage here
   is that the history looks as if the projects had always been part of
   the repo, so there is no big rename event. You can even annotate the
   commit messages to indicate which project is being worked on.

   The downside, of course, is that having rewritten history, merges
   with the original project become more difficult. But that is not a
   problem if you are going to throw away the original repositories.

   You can accomplish this with filter-branch:

     mkdir merged && cd merged && git init
     for lib in lib1 lib2; do
       git fetch /path/to/$lib master:$lib
       git checkout $lib
       git filter-branch -f \
         --index-filter '
             git ls-files -s |
             sed "s,\t,&'$lib'/," |
             GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
               git update-index --index-info &&
               mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' \
         --msg-filter "sed '1s/^/[$lib] /'" \
         $lib
     done

   and then merge the resulting branches as usual.

Hope that helps.

-Peff

      reply	other threads:[~2008-11-04  4:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-04  3:33 Merging two projects Andrew Arnott
2008-11-04  4:56 ` Jeff King [this message]

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=20081104045644.GC31276@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=andrewarnott@gmail.com \
    --cc=git@vger.kernel.org \
    /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