interactive/visual merge tool for console?

15,998

Solution 1

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

Solution 2

You can use vim -d file1 file2 for that.

Solution 3

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.

Solution 4

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

Share:
15,998
Andreas Gohr
Author by

Andreas Gohr

Updated on September 17, 2022

Comments

  • Andreas Gohr
    Andreas Gohr almost 2 years

    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?

  • Daniel Ozean
    Daniel Ozean over 13 years
    @How to merge/copy changes from on file to another using vimdiff or vim -d
  • simlev
    simlev over 5 years
    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.
  • Gabriel Staples
    Gabriel Staples over 3 years
    sdiff doesn't seem to have any coloring or highlighting options to highlight differences. This makes it very rudimentary and difficult to use.
  • GrAnd
    GrAnd over 3 years
    Actually, it does support merging to the right: F15 (or Shift+F5).
  • GrAnd
    GrAnd over 3 years
    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.
  • Bernardo Ramos
    Bernardo Ramos over 3 years
    Thanks for the info! Updated
  • fbmd
    fbmd over 3 years
    @GabrielStaples I did not advertise anything else. It does basic highlighting of common and changed lines, though.
  • Gabriel Staples
    Gabriel Staples over 3 years
    @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.
  • fbmd
    fbmd about 3 years
    @GabrielStaples That's what I meant by highlighting. Not all terminals support color under all circumstances, so that is one of the most portable ways to highlight differences.