15

I have two code bases, Code base-1, Code Base-2.

I run the commands ...

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

... in 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?

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
Berlin Brown
  • 11,504
  • 37
  • 135
  • 203

3 Answers3

8

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
4

Try:

cd code-base-1
git fetch ../code-base-2 master:code-base-2
git merge code-base-2
Fake Code Monkey Rashid
  • 13,731
  • 6
  • 37
  • 41
-2

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
  • 1,929
  • 23
  • 31
  • 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/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. – Berlin Brown Jul 17 '09 at 03:51