Interactively merge 2 different files unter Linux

Every Linux sysadmin knows the pain: You update a package, and suddenly you have a

,

, or

file sitting next to your carefully tuned configuration.

Do you keep your old file? Do you overwrite it with the new defaults? Don’t just copy-paste!

Here are the three best ways to interactively merge these files, including a dark-mode friendly “Cheat Sheet” for the most powerful tool of them all.


1. The Power User Way:

If you have Vim installed, this is the gold standard. It opens both files side-by-side, highlights the differences, and folds away the parts that are identical.

The Command

The Vimdiff Cheat Sheet

Navigating Vim can be scary, but you only need these 5 commands to merge files:

Key Action Mnemonic
Jump to Next Change
Jump to Previous Change
Pull change from other window to yours Diff Obtain (Get it)
Push change from yours to the other Diff Put (Send it)
Save All files and Quit eXit All

2. The Simple Interactive Way:

If you don’t want to memorize keyboard shortcuts,

is a fantastic alternative. It runs in the terminal and asks you line-by-line which version you want to keep.

The Command

It will pause at every difference and show a prompt (

). Just type one of these letters and hit Enter:

  • l : Choose the Left file’s version.
  • r : Choose the Right file’s version.
  • eb : Edit Both (opens a mini-editor to combine them).

3. The Graphical Way: Meld

If you are on a desktop environment (Ubuntu, Fedora, Mint), nothing beats Meld. It provides a visual 3-column or 2-column view where you can simply click arrows to move code blocks around.

The Command

Tip: You can hold down CTRL while clicking the arrow to insert the new lines above/below instead of replacing the old ones!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.