views:

195

answers:

3

Does anyone know of an Open Source three-way merge implementation in JavaScript or PHP? I want to merge plain text files without the need to rely on any server side binaries.

I found a few solutions for creating diffs, but no merge implementations.

A: 

Not sure if I understand, but

$files = array('file1.txt', 'file2.txt', 'file3.txt');
$out = '';
foreach($files as $file) {
  $out .= file_get_contents($file);
}

file_put_contents('merged.txt', $out);
michal kralik
No, that's concatenation. He wants to merge text files as a source control program would. http://en.wikipedia.org/wiki/Merge_(revision_control)#Three-way_merge
Nosredna
I guessed, but I gave it a shot anyway :P
michal kralik
A: 

Synchrotron looks good. E.g. see the demo of three-way merge and conflict-handling.

Beni Cherniavsky-Paskin
Yes, looks great. Thank you very much!
Andreas Gohr
Synchrotron seemed to have some bugs when merging for me, but it may work for you. I'd be interested if there are any other JavaScript libraries
Knio
A: 

Not exactly three-way merge, but Google's "Diff Match and Patch libraries offer robust algorithms to perform the operations required for synchronizing plain text". And the implementation is available in Java, JavaScript, C++, C#, Lua and Python.