Get the highlights in your inbox every week.
Don't love diff? Use Meld instead | Opensource.com
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.
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:
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
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:
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:
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):
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:
ConclusionEven 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.