Re: Merging two projects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux