31

I'm a big fan of meld - a visual diff and merge tool for Gnome. It shows two files (or directories) side-by-side and with their differences highlighted, and I can easily select which parts I want to move from one file to the other.

I'm looking for a similar tool, but it should work on the (Linux) console, eg. it should not require any X server. Maybe using an ncurses interface.

Is there such tool?

1

4 Answers 4

18

Ah just found out about vimdiff. It pretty much does what I was looking for. here's a quick guide

1
  • 1
    @How to merge/copy changes from on file to another using vimdiff or vim -d
    – goldenmean
    Nov 16, 2010 at 15:12
9

You can use vim -d file1 file2 for that.

8

sdiff, a classic command line tool which shows text file differences side by side, also has an interactive merge mode. Use it by running

$ sdiff -o output.txt input1.txt input2.txt

It is the default interactive command line merge tool used by Gentoo Linux' etc-update utility.

Advantages over vimdiff are ubiquitous availability and much simpler handling.

6
  • Easy to use, just press 1 or 2 to choose the wanted version. However, columns are truncated to only show 60 charcartes, and changes must be saved to a third file.
    – simlev
    Jan 7, 2019 at 10:51
  • 2
    sdiff doesn't seem to have any coloring or highlighting options to highlight differences. This makes it very rudimentary and difficult to use. Feb 23, 2021 at 17:40
  • @GabrielStaples I did not advertise anything else. It does basic highlighting of common and changed lines, though.
    – fbmd
    Feb 24, 2021 at 18:29
  • 1
    @fbmd, sdiff file1.h file2.h doesn't show any color for me whatsoever. How do you get it to show color? it shows various | chars in the middle indicating contents on left and right are the same, and < and > chars showing left and right are different, but it has no color whatsoever. sdiff --version shows this version: sdiff (GNU diffutils) 3.6. Feb 24, 2021 at 19:05
  • 1
    Nice. In interactive mode: h for help. I find ed to be most useful: edit both (decorated with a header). Nov 4, 2022 at 12:30
7

I use the Midnight Commander for this. Select a file on the left pane and another on the right, press F9, then Command > Compare Files.

It can also be called using the mcdiff command

Use Enter to navigate to the next diff, F5 to merge the selected diff from the right to the left and F15 (or Shift + F5) from left to right.

It is possible to change the keybindings (useful on Mac):

On mc.keymap file section [diffviewer] change from:

MergeOther = f15

To:

MergeOther = f6

If you want F6 to be the default key for this, ask here

More info on F1

3
  • Actually, it does support merging to the right: F15 (or Shift+F5).
    – GrAnd
    Feb 23, 2021 at 18:04
  • 2
    Also, you can modify files during merging using F4 (of F14, Shift+F4 for the right pane). It will open partially merged file for editing in the position of last merge. So you can change what you want, save changes and exit from edit mode and it will return back to mcdiff to continue merging with updated file.
    – GrAnd
    Feb 23, 2021 at 18:18
  • Thanks for the info! Updated Feb 23, 2021 at 20:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .