Don't love diff? Use Meld instead

Meld is a visual diff tool that makes it easier to compare and merge changes in files, directories, Git repos, and more.
121 readers like this.

Meld is one of my essential tools for working with code and data files. It's a graphical diff tool, so if you've ever used the diff command and struggled to make sense of the output, Meld is here to help.

Here is a brilliant description from the project's website:

"Meld is a visual diff and merge tool targeted at developers. Meld helps you compare files, directories, and version controlled projects. It provides two- and three-way comparison of both files and directories, and has support for many popular version control systems.

"Meld helps you review code changes and understand patches. It might even help you to figure out what is going on in that merge you keep avoiding."

You can install Meld on Debian/Ubuntu systems (including Raspbian) with:

$ sudo apt install meld

On Fedora or similar, it's:

$ sudo dnf install meld

Meld is cross-platform—there's a Windows install using the Chocolately package manager. While it's not officially supported on macOS, there are builds available for Mac, and you can install it on Homebrew with:

$ brew cask install meld

See Meld's homepage for additional options.

Meld vs. the diff command

If you have two similar files (perhaps one is a modified version of the other) and want to see the changes between them, you could run the diff command to see their differences in the terminal:

diff output

This example shows the differences between conway1.py and conway2.py. It's showing that I:

  • Removed the shebang and second line
  • Removed (object) from the class declaration
  • Added a docstring to the class
  • Swapped the order of alive and neighbours == 2 in a method

Here's the same example using the meld command. You can run the same comparison from the command line with:

$ meld conway1.py conway2.py

Meld output

Much clearer!

You can easily see changes and merge changes between files by clicking the arrows (they work both ways). You can even edit the files live (Meld doubles up as a simple text editor with live comparisons as you type)—just be sure to save before you close the window.

You can even compare and edit three different files:

Comparing three files in Meld

Meld's Git-awareness

Hopefully, you're using a version control system like Git. If so, your comparison isn't between two different files but to find differences between the current working file and the one Git knows. Meld understands this, so if you run meld conway.py, where conway.py is known by Git, it'll show you any changes made since the last Git commit:

Comparing Git files in Meld

You can see changes made in the current version (on the right) and the repository version (on the left). You can see I deleted a method and added a parameter and a loop since the last commit.

If you run meld ., you'll see all the changes in the current directory (or the whole repository, if you're in its root):

Meld . output

You can see a single file is modified, another file is unversioned (meaning it's new to Git, so I need to git add the file before comparing it), and lots of other unmodified files. Various display options are provided by icons along the top.

You can also compare two directories, which is sometimes handy:

Comparing directories in Meld

Conclusion

Even regular users can find comparisons with diff difficult to decipher. I find the visualizations Meld provides make a big difference in troubleshooting what's changed between files. On top of that, Meld comes with some helpful awareness of version control and helps you compare across Git commits without thinking much about it. Give Meld a go, and make troubleshooting a little easier on the eyes.


This was originally published on Ben Nuttall's Tooling blog and is reused with permission.

What to read next
Tags
User profile image.
Ben is a software engineer for BBC News Labs, and formerly Raspberry Pi's Community Manager. He's into Linux, Python and all things open source! Follow Ben on Twitter @ben_nuttall.

6 Comments

Nice article, I like Meld!

Will definitely be trying out Meld. Thanks for sharing :)

I adopted Meld since you mentioned it to me Ben, and I'm absolutely loving it. The auto-detection by git it's quite handy as well. Thanks for sharing!

It's very out of date now, but I still really like the display style of cs-diff. It shows a single view of the file, with the differences annotated. New lines/text is highlighted, and deleted stuff is crossed out / struck through.

I've not found a more up to date tool which provides that option.

Good article. I also liked it.

A caution about meld, I manage a number of CentOS 6 (yeah, we're going to 7 "real soon now") and my users like to use meld, but on a few occasions it's missed some diffs. Unfortunately, I'm usually too swamped to investigate. Perhaps a current version might not have that issue.
But, I still like meld for the nice graphical interface.
There's also tkdiff which comes with the tkcvs package.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.