KDiff3: File Comparison and Merging Tool

Ashwin Karthik
Updated •
Software

KDiff3 is an open-source graphical tool designed for comparing and merging two or three text files or directories, highlighting differences line-by-line and character-by-character. It is widely used for version control, providing an automated merge-facility and an integrated editor to resolve conflicts. It works on Linux, Windows, and macOS. KDiff3 is a KDE project.

KDiff3 is an open source, cross-platform file comparison and merge tool

How to use KDiff3?

Unlike some comparison tools, KDiff3 is capable of three-way comparisons, i.e., you may use it to select up to 3 files or folders for comparison or merging.

Run the program and you'll see a pop-up window overlapping the interface. Select the files or folders to be processed. Let's try it with a couple of documents. The application loads one document in each pane. The differences in the content are highlighted on a color-coded basis.

KDiff3 comparison example

The interface of KDiff3 is made up of a menu bar and a toolbar. The File and Edit menu are for performing basic operations like opening, saving, copy, paste, cut, etc. The address bar at the top of each pane shows the name and the full path of the loaded file. There is a status bar below it that displays the current line number, the encoding format and line end style of the document.

Use the Diffview menu for additional options such as Word Wrap, Diff Windows, add or clear manual alignment, toggle the line numbers, space and tabulator characters, whitespace. Jump to the next conflict, i.e., difference in the content, by using the movement menu.

When the documents contain whitespace at the same lines, a conflict occurs, and you'll have to use the Merge menu to decide which content should be saved in the output document. And since this is a new file, it does not affect the ones which are being merged. You can also right-click on a conflict to view a context menu that allows you to choose which line to use, the one from Document A or B.

kdiff3 merge conflict

This is a fantastic way to observe the changes made between two or three revisions of a document, without manually having to go over it.

KDiff3 Folder Comparison and Operations

KDiff3 can also be used to compare folders and if required, merge them. Comparing 2 folders displays a summary that tells you the total number of files in the directories, how many of those are the same, and the number of different files. Click ok to view the actions that you can choose. Once again it is presented in a color-coded form, and you can see which files exist in Folder A, the ones in Folder B, and the common ones.

Kdiff3 folder comparison

The Folder Menu is activated when you select two directories for comparison. This allows you to merge the folders or specific files. You can also compare selected files. The results can be toggled to show identical files, different files, only those in A or B.

Kdiff3 folder comparison options

For quick operations, you can use the menu item that lets you select all files in a folder. Once you have selected some files for merging or synchronization. Select the Current Item Merge or Current Sync Operation and pick the folder to be used as the source. You can optionally select the "Delete (if exists)" or Do Nothing option to delete or retain the files in the destination folder.

When you're ready, hit F7 or the Start/Continue Folder Merge option to apply the changes. You'll be given an option to simulate the result, which displays a log of the changes that will take place if you actually proceed with the operation. In this example, I  have opted to select folder A as the source. So the contents will be copied to folder B.

kdiff3 folder merge simulation

KDiff3's Options screen can be accessed from the settings menu. It lets you customize the font type, size, colors used for the difference indicators. There are some advanced options that you can define for the merge, folder settings.

Installers for the Windows version of KDiff3 are available at the Binary Factory page. The program is is also available for Linux from the KDE website. There is an older version on SourceForge that is missing some features.

If this isn't your cup of tea, Meld is a good alternative, that's also open source and cross platform.

KDiff3 vs Meld

Both KDiff3 and Meld are excellent, free, and open-source (FOSS) visual diff/merge tools, but they cater to slightly different needs. KDiff3 is generally preferred for complex, three-way merge conflicts (especially with Git) and advanced, feature-rich analysis. Meld is often chosen for its simplicity, cleaner user interface, and faster, more intuitive daily, two-way, or three-way comparisons.

Comments

  1. murray602 said on
    Reply

    Sorry- I totally missed the .exe file… thanks for the tip

  2. murray602 said on
    Reply

    I would appreciate any pointers on how to convert these binary(?) files into window executables. I assume these are compiled for Linux which I am unfamiliar with. There must be an app somewhere but I don’t know where to start. Thanks

    1. Martin Brinkmann said on
      Reply

      As Ashwin mentioned in the article, installers for Windows are found here: https://binary-factory.kde.org/view/Windows%2064-bit/job/KDiff3_Nightly_win64/

      1. bawldiggle said on
        Reply

        [b] kdiff3-master-21-windows-msvc2017_64-cl-dbg.7z
        [a] kdiff3-master-21-windows-msvc2017_64-cl-dbg.7z.sha256
        kdiff3-master-21-windows-msvc2017_64-cl.7z
        kdiff3-master-21-windows-msvc2017_64-cl.7z.sha256
        [c] kdiff3-master-21-windows-msvc2017_64-cl.exe . . . . . 50MB
        kdiff3-master-21-windows-msvc2017_64-cl.exe.sha256

        Which one is for Windows ?
        [a] is not for Windows , Virus Total returns a blank report
        [b] when extracted it has 119 EXE files, none that resemble a primary EXE
        [c] Virus total returns a risk score of 1/67 but the VT report is empty. No AVs list

        I started to install [c] but got feet …
        Not for the feint hearted.

      2. Martin Brinkmann said on
        Reply

        Number c is the right one that you can install.

      3. bawldiggle said on
        Reply

        ie, cold feet

  3. Artem said on
    Reply

    Meld is much more convenient

  4. Ascrod said on
    Reply

    I’ve used KDiff3 on Windows for years, since for a long time it came bundled with GitExtensions. I’ve had weird issues with it on Mint lately, so I’ve started using meld there instead. Still an excellent diff tool nonetheless.

  5. Anonymous said on
    Reply

    forgot to ask: can it produce patch files made from the diff?

  6. Anonymous said on
    Reply

    binary files arent supported i guess?
    edit: yes, homepage says so. (maybe add that important piece of info above?)

  7. B said on
    Reply

    How about WinMerge?

  8. Buzz said on
    Reply

    This looks like a great program that I would like to try. Clicking on the link in the summary box at the end of the post brings me to a page with an “Install” button, but clicking it brings up an empty page saying “The address wasn’t understood”. I am using Firefox, how can I download and install this program?

    1. Ascrod said on
      Reply

      The KDE link on the page is only for Linux distributions. The Windows version is a little old, but still works quite well and can be found here: http://kdiff3.sourceforge.net/

      @Ashwin can perhaps make a note of this?

      1. Buzz said on
        Reply

        Thanks Ascrod. Your insturctions worked.
        Buzz

      2. Ofiri said on
        Reply

        If you want to see the latest version (the one on sourceforge.net is quite old), you can download the installation binary from project page kde.org:

        https://binary-factory.kde.org/view/Windows%2064-bit/job/KDiff3_Nightly_win64/

        Here they are building the code from the project repo every night.

  9. ZeN said on
    Reply

    I’ve been looking for this type of software for a while now, thanks Ashwin, for the heads up!

    Apart from Meld any other recommendations from the populous would be appreciated too. Thanks in advance. -Z-

Leave a Reply

By commenting, you accept our privacy policy and keep the discussion respectful and on topic.