tags:

views:

593

answers:

3

If I have a code base. Code base-1, Code Base-2.

I run the command:

git init
git add .
git commit -m "Initial Commit"

Into both repositories (directories).

There are code differences between code base-1 and code base-2

I can't branch them because they already contain differences of about 0.1%. The filenames are the same but there are some slight edits to the code.

Is there a way to merge the differences between the two repositories?

Edited:

For example, let's say I have the following. This is what I am starting out with. There are slight differences between codebase 1 and 2.

[oldest code case] 
code-base-1/ 
code-base-1/.git  [git stuff with already created repo] 
code-base-1/file1 
code-base-1/file2 

code-base-2/ 
code-base-2/.git [git stuff with already created repo] 
code-base-2/file1 
code-base-2/file2

Ideally, I could delete code-base-2 because it is a little newer. How would I merge these code bases? So that I eventually come out with one with the merged files.

A: 

Create the first repository as you have described.

In the second folder create a file called ".git" with the contents:

gitdir: <path-to-first-repository>/.git

In the second repository you can now run git diff, git add/commit etc. to merge in your changes.

David Plumpton
Could be a little more specific. For example, let's say I have the following. This is what I am starting out with. There are slight differences between codebase 1 and 2.[oldest code case]code-base-1/code-base-1/.git [git stuff with already created repo]code-base-1/file1code-base-1/file2code-base-2/code-base-2/.git [git stuff with already created repo]code-base-2/file1code-base-2/file2Ideally, I could delete code-base-2 because it is a little newer.How would I merge these code bases. So that I eventually come out with one with the merged files.
Berlin Brown
That comment didn't format correctly, see above.
Berlin Brown
+2  A: 

Try:

cd code-base-1
git fetch ../code-base-2 master:code-base-2
git merge code-base-2
Fake Code Monkey Rashid
This would join two versions of the same project like they were different projects (if they have no common commits of cours).
Jakub Narębski
+3  A: 

The problem might comes from the fact those are two different repository (with a different SHA-1 first node), and not one repo cloned and then modified.
That means a 'git fetch' is probably not enough.

You could simply use an external tool (external to Git that is) to merge the content of CB2 (Code-Base-2) into CB1, like WinMerge as suggested in the question "Merging in changes from outside a git repository".

The other option would be using some graft technique to complete a fetch: see the question "Can two identically structured git repos be merged when they have never had any common history?"

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

Plus modify the graft file (.git/info/grafts) to link the commits of project2 to project1.

VonC