8

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.

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
Andreas Gohr
  • 4,617
  • 5
  • 28
  • 45

3 Answers3

6

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.

user207825
  • 71
  • 1
  • 3
  • 1
    This is the best answer. While I understand links are not desired on SO, the authors of `diff-match-patch` provide an example of a 3-way merge that may be helpful for others using this library: https://neil.fraser.name/software/diff_match_patch/demos/patch.html – Harley Lang Dec 27 '21 at 19:09
3

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

Beni Cherniavsky-Paskin
  • 9,483
  • 2
  • 50
  • 58
  • 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 Sep 17 '10 at 08:58
1

Just finished my work on such a js- and php-tool. Have a look and enjoy:

https://github.com/Krassmus/Textmerger

You'd just need to write

var merged = Textmerger.get().merge(original, mytext, theirtext);

or in PHP

$merged = Textmerger::get()->merge($original, $mytext, $theirtext);

and you're done.

Krassmus
  • 349
  • 2
  • 6