114

Requirements:

  • free, preferably open-source
  • implemented in one of the .NET managed langs

Google found these:

EDIT:

No apps please, only libraries.

aku
  • 122,288
  • 32
  • 173
  • 203
  • 5
    This thread hasn't been trafficked in a while, but which open source diff project did you end up going with? I'm looking for the same and besides the libraries listed I haven't found much (disappointed that so little has changed in 2 years...). – marr75 Aug 02 '10 at 14:21
  • 1
    marr75: here you go [Credit to Cheeso / Brian (see answers below)]: "The [Google Diff/Patch/Merge code](http://code.google.com/p/google-diff-match-patch/) has been ported to C#. The COM component still works, but if you're coming from .NET, you'll wanna use the .NET port directly." – Dave May 19 '11 at 22:09
  • 2
    I agree this answer was very helpful, it is requesting an engine or algorithm for a very specific programming problem, and I nominated it for reopen. – Mladen Mihajlovic Sep 11 '19 at 05:07

4 Answers4

92

You can grab the COM component that uses Google's Diff/Patch/Match. It works from .NET.

Update, 2010 Oct 17: The Google Diff/Patch/Merge code has been ported to C#. The COM component still works, but if you're coming from .NET, you'll wanna use the .NET port directly.

Community
  • 1
  • 1
Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • 14
    Looks like this has been ported to C# (full managed C# implementation). The C# version is availble in the download section on the Google page. You can edit out the "COM" bit of your answer. Nice find as this implementation (at least the python/js versions) are used in some widely-used projects such as Google Docs. – Brian Low Oct 05 '10 at 16:21
  • 7
    Very useful answer in 2015. Please do not delete, Site would be more useful if this type of thing were allow (read: another site will allow this, and more, and rise up and turn SO into experts-exchange if useful questions like this keep getting closed for reasons based on the faulty hypothesis in the SO faq). – FastAl Apr 11 '15 at 20:29
  • Agree that the google version works well and is easy to use – Johan Danforth Jun 15 '17 at 12:29
  • 2
    I recommend [DiffPlex](https://github.com/mmanela/diffplex). It is `netstandard1.0` and very light weight. You can easily embed it in your WPF application using the `RichTextBox` like this: https://github.com/halllo/WpfDiff – halllo Jul 22 '17 at 15:51
  • 1
    A more C#-centric port (naming, casing, etc.) is at: https://github.com/pocketberserker/Diff.Match.Patch with nuget support: `Install-Package Diff.Match.Patch` – Kirk Woll Jun 22 '18 at 04:56
  • 1
    pocketberserker's `Diff.Match.Patch` is actually more F#-centric, and depends on F# Core libraries. – StriplingWarrior Oct 03 '18 at 20:53
23

I think the "Generic - Reusable Diff Algorithm in C#" on Codeproject is the best you can find as a .NET-Engine for diff/patch/merge. I made a project on my own with it and it fits my needs with most scenarios. There are one or two worst-case scencario when the algorithm made the patch-file larger than it have to be. But in most of the cases it works just fine for me (textfiles with a size of >30 MB).

I'm currently testing another Codeproject-Project you can find here: http://www.codeproject.com/KB/applications/patch.aspx It's using some DLLs from Microsoft for patching, so it looks interesting. But those DLLs are unmanaged and this project is only some sort of wrapper for it. But maybe it can help you

Edit: Just found another project, DiffPlex: http://diffplex.codeplex.com/ It's a combination of a .NET Diffing Library with both a Silverlight and HTML diff viewer. As stated there, DiffPlex is the library that CodePlex leverages to generate the diffs of files.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Anheledir
  • 4,337
  • 7
  • 32
  • 34
  • thanks for info! but I hope to find more sophisticated solution. I just can't believe nobody created some neat lib – aku Sep 26 '08 at 09:35
  • 1
    When you find a better library, please tell us (or at least me *g*) - I searched myself quite a while and didn't find anything beside the already mentioned. – Anheledir Sep 28 '08 at 00:14
  • 2
    Diffplex has moved to https://github.com/mmanela/diffplex – codingdave Jun 14 '17 at 09:35
5

None of the answers so far (except possibly the GitSharp reference) deal with 3-way merge, so in case it helps anyone I recently ported Tony Garnock-Jones' javascript diff3 implementation (from the synchrotron project, based on Hunt and McIlroy 1976) to C#.

It's a simplistic single-file port of diff and three-way merge methods, but it's the standard algorithm and so far works very well for me: https://gist.github.com/2633407

Tao
  • 13,457
  • 7
  • 65
  • 76
  • I cannot resolve the gist.github link - I wonder if the three way merge method could be integrated into a [tool like this](https://github.com/Dirkster99/Aehnlich) and whether it returns different results or is in fact the same as the [Myers Diff](https://github.com/Dirkster99/Aehnlich/blob/master/source/AehnlichLib/Text/MyersDiff.cs) algorithm that is already implemented? – user8276908 Mar 06 '19 at 20:05
5

GitSharp includes a diff engine based on meyers diff. Take a look at the demo which implements a simple wpf diff viewer based on the Diff.Sections collection: http://www.eqqon.com/index.php/GitSharp#GitSharp.Demo

henon
  • 2,022
  • 21
  • 23