tags:

views:

271

answers:

1

I have two small git repos. The projects both started from different points but converged to a very similar one (same file names, folder structure, etc). One is not a branch of the other, but one can be considered an evolution of the other.

It would be nice if I could merge the two so that repo2 is the continuation of repo1. Is this possible, whilst adding the history of repo2 to the end of repo1's?

Kind Regards

+3  A: 

You can fetch one into another:

$ cd project1
$ git config remote.project2.url /path/to/project2
$ git config remote.project2.fetch 'refs/heads/*:refs/project2/*'
$ git fetch project

That will give you two (or more) branches, containing history of the project1 and project2. They are still completely independent, just use the same object store.

Then (not tested), you could use a graft file (.git/info/grafts) where you could overwrite the parenthood of a commit (like the first of project2 having for parent the latest of project1)

As Dustin says in the comments, a rebase is in order in order to "make it permanent", by replaying project2 commits onto project1.


You have another illustration in this "Using Git within a project (forking around)" blog entry, especially the section "How to pull friends and influence people". Again:

git checkout two_point_ooh
git remote add strelau git://gitorious.org/ruby-on-rails-tmbundle/mainline.git
git checkout -b strelau/two_point_ooh
git pull strelau two_point_ooh

is a similar process, but for repositories which are forked (which is not exactly your case)

VonC
Note that you should rebase after the graft to sort of make it "permanent."
Dustin