Linux.com

Feature

Comparing and merging files with Meld

By Nikos Kouremenos on April 17, 2007 (8:00:00 AM)

Share    Print    Comments   

When you're editing text, you may find yourself with two or three similar versions of a file. Often you are not sure which file has what content, what was deleted in one, what was added in another, and where exactly. You know what content your file should contain, but you are not sure which version to start from. It's one of those moments you wish your computer were smart enough to understand your problem and fix it for you. Well, that's not going to happen, but there is an open source application that you can run to help. Meet Meld, a visual diff and merge tool.

With Meld you can compare two or three files and edit them in place (diffs update dynamically). You can compare two or three directories and launch file comparisons. And lastly, you can browse and view a working copy from a popular version control systems such as CVS, Subversion, Bazaar, or Mercurial.

Meld is easy to install -- just untar and run it. You may want to run make to generate translations. Alternatively you can make a symlink to the untarred executable by typing ln -s melddir/meld /usr/local/bin/meld, or type make prefix=/usr/local install and you will have the Meld executable in /usr/local/bin/.

The project offers packages for many distributions, including Debian, Fedora, Gentoo, Slackware, and Arch Linux, as well as FreeBSD and Solaris.

Since Meld is a GNOME application written in Python, it depends on the gnome-python library to run, and if you want syntax highlighting in your documents, make sure you have gtksourceview installed.

Meld offers three kinds of viewing differences and doing comparisons: file comparison, directory comparison, and version control browser.

File comparison

With file comparison, you compare two or three files to find and then work on the differences.

Meld file comparison
File comparison - click to enlarge
To start, choose File -> New. In the File Comparison tab point to the files you want to compare by clicking the Browse button and selecting each file. When ready, click OK. In the display window, lines and characters that differ between the files are highlighted with different colors. Where you see black arrows between the two files, you can click on them to pass the content of one file to the other. In this example, if you click on the arrow pointing to the right next to the Peace and stability paragraph, Freedom (on the right) will be replaced by the text that has a cyan background on the left. If you need to undo, press Ctrl-Z.

Let's say that for some reason you want to add the Peace and stability cyan-highlighted section from the left document above of the Freedom highlighted section of the right document. Hold down the Ctrl key and notice that the single arrow gets replaced by two arrows pointing up and down. Click the one pointing up, and there you have it -- the text in question from the left document is added above of the text of the right document. When you're happy with the result, you can save the changes you've made by clicking the Save Button.

Meld directory comparison
Directory comparison - click to enlarge
Directory comparison

With directory comparison, you compare two or three directories to discover and then work on differences in their contents. Choose File -> New, and in the Directory Comparison tab point to the directories you want to compare the same way you selected files above. Notice again the use of colors in the comparison pane. be@latin.po is green; it is a new file and as such is missing from the gajim_orig directory. In the same window, de.po is red, which means files differ. You can double-click a file to start a file comparison. Click the Down and Up buttons to travel between the files that have been marked by Meld as different, new, or missing. If you find a file that has two versions and want to keep only one of them, select the version you want to keep and click the Left or Right button (depending from which directory you copy).

Finally, Meld can also act as a version control browser for examining and committing or reverting local changes. Keep in mind though that it is not intended to be a complete version control client.

Stephen Kennedy, the main developer of Meld, has created a powerful tool. If the colors and possible actions confuse you at first, either stick to the basics and learn more progressively, or try reading the Help text. Power users should read the Filtering section in File Comparison chapter of the Help, as it allows you to ignore certain types of differences in order to locate only important differences, which can be useful when you're working with long text files.

Nikos Kouremenos is a computer science student who has been active in the open source community since 2002.

Share    Print    Comments   

Comments

on Comparing and merging files with Meld

Note: Comments are owned by the poster. We are not responsible for their content.

slow

Posted by: Anonymous Coward on April 17, 2007 05:36 PM
You could have mentioned that although meld is nice, it gets verrry slow even with smaller amount of text. It's good to compare, but painful to edit, due to speed issues. The GUI idea however, is great.

#

Re:slow

Posted by: Administrator on April 17, 2007 05:43 PM
Hmm. I haven't had any problems with Meld being slow with smaller amounts of text. I run huge and small diff's on both large and small files on a daily basis, both on two local copies and local CVS, but haven't had any speed problems so far.

Anyway, Meld is a great tool. It's made my life as a developer a thousand-fold easier. Just yesterday I had to do a manual verification of a changeset containing 800+ changes - some of which needed to be applied, others which didn't - and with Meld I was done in about an hour.

Many thanks for Stephen and all the other people that contributed to this project for making such a valuable tool.

#

Re(1):slow

Posted by: Anonymous [ip: 83.131.34.47] on September 12, 2007 10:40 PM
I just run Meld accros two /home directories (I was stupid then upgrading my PC...), both have around 2 gigs of files (mainly postgres clusters) with some 600 megs that are not shared between those two... It runs for almost 20 minutes now. Diff -r runs much faster (2 minutes), but I tought that tool with GUI would make my 'merge' job easier..

#

For the CLI geeks

Posted by: Anonymous Coward on April 17, 2007 05:39 PM
A very nice tool to do the same job is imediff2 (although only for files, for directories, there's unison).

Basic usage : imediff2 -o OutputFile File1 File2

Then use TAB to jump to the next difference, Enter to toggle version A or version B, x and s to save and exit. See the manpage for the rest of the commands.

#

Re:For the CLI geeks

Posted by: Anonymous Coward on April 18, 2007 01:48 AM
There's also <a href="http://www.vim.org/htmldoc/diff.html" title="vim.org">vimdiff</a vim.org>

#

Krusader &amp; KDiff3 for KDE

Posted by: Anonymous Coward on April 17, 2007 08:42 PM
Meld seems like a very nice utility for GNOME users but there's also a similar application for us KDE users.

The KDE file manager Krusader has a similar directory synchronization function as Meld and Krusader can also call your favourite diff utility to compare & merge individual files. I would recommed KDiff3 as the diff-merger to be used with Krusader.

<a href="http://krusader.sourceforge.net/handbook/synchronizer.html" title="sourceforge.net">http://krusader.sourceforge.net/handbook/synchron<nobr>i<wbr></nobr> zer.html</a sourceforge.net>
<a href="http://kdiff3.sourceforge.net/" title="sourceforge.net">http://kdiff3.sourceforge.net/</a sourceforge.net>

#

Re:Krusader &amp; KDiff3 for KDE

Posted by: Anonymous Coward on April 18, 2007 07:19 AM
Meld is nice but I think kdiff3 is better. Kdiff3 allows comparison of files using URLs. Its also available for WinXP where it integrates well with file explorer (using right click) to enable easy comparison of files in different subdirectories.

#

Re:Krusader &amp; KDiff3 for KDE

Posted by: Anonymous Coward on April 18, 2007 10:56 PM
KDE has Kompare. Much nicer than Meld.

#

Re(1):Krusader &amp; KDiff3 for KDE

Posted by: Anonymous [ip: 83.131.34.47] on September 12, 2007 10:46 PM
Kompare is about the slowest utility for that kind of work. I often need to compare huge directories with a lot of JPEGs (cca 10 Gigs of data, around 50.000 files), and diff -r along with finddupes from perforate package are much much faster. I agree that 10 Gigs is a lot, but Kompare is unbelievable slow. I run a test with two directories aroung 1 Gb in size each, it took Krusader more than 30 minutes to finish the job. Needles to say that finddupes (wich is, btw, a Perl script!) was MUCH quicker - around a minute! My machine is 1.7 Ghz P4 (Willamette core) with 768 megs of memory.

#

Emacs merge mode

Posted by: Anonymous Coward on April 18, 2007 03:27 AM
And of course there's, what else, emacs. It has a merge mode that has comparable functionality.

Karl O. Pinc

#

Great tool

Posted by: Anonymous Coward on April 18, 2007 10:50 AM
I have been working on one similar project on two sites (lot of last minute changes, need to CVS), and was looking for something that gives me a good diff/compare/edit to re-sync the two codebases and this one does the trick really nicely.

It made my evening! Thanks for the tip!!

BTW you can get it through Adept in Ubuntu Dapper Drake

#

gvimdiff

Posted by: Anonymous Coward on April 18, 2007 11:24 AM
VI clone gvim can be used as a GUI based diff tool... It called 'gvimdiff'. It can be used to dinamically edit any of two (or more) files.

I am using it for at least 4-5 years... so nothing new

#

For Windows

Posted by: Anonymous Coward on April 18, 2007 12:42 PM
For those of us stuck on Windows for development I can heartily recommend <a href="http://sourceforge.net/projects/winmerge/" title="sourceforge.net">http://sourceforge.net/projects/winmerge/</a sourceforge.net> Though I am verrrry happy that there are linuxy tools that do the same thing.

#

Re:slow

Posted by: Anonymous Coward on April 26, 2007 02:51 AM
i am running 1.1.3 version from debian. On 50kb file it gets slow. The machine is Pentium Centrino 1.73 with 1GB RAM. If it works fine for you, i will try to upgrade it, perhaps that's the problem. Otherwise a great tool!

#

Comparing and merging files with Meld

Posted by: Anonymous [ip: 84.164.246.14] on September 14, 2007 05:01 PM
In my opinion this is probably the best diff/compare gui tool available for linux. It plays in the same league as Araxis merge, which is unfortunately only available for windows. It has almost the same set of features (it even allows full screen editing with live diff update!). However, both tools probably don't fit for comparing large MP3 or video libraries, but there are other tools for that. When it comes to development and/or serious version control, then meld rocks!
The only thing missing for me is better integration in KDE - it would be fantastic if meld could use the kio slave functions to transparently access remote files/directores, ...
Many thanks to the programmers!

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya