interactive/visual merge tool for console?
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
Andreas Gohr
Updated on September 17, 2022Comments
-
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?
-
Gabriel Staples over 3 yearsSee also (same Q on Stack Overflow): stackoverflow.com/questions/1991248/….
-
-
Daniel Ozean over 13 years@How to merge/copy changes from on file to another using vimdiff or vim -d
-
simlev over 5 yearsEasy to use, just press
1
or2
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 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 over 3 yearsActually, it does support merging to the right:
F15
(orShift
+F5
). -
GrAnd over 3 yearsAlso, you can modify files during merging using
F4
(ofF14
,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 tomcdiff
to continue merging with updated file. -
Bernardo Ramos over 3 yearsThanks for the info! Updated
-
fbmd over 3 years@GabrielStaples I did not advertise anything else. It does basic highlighting of common and changed lines, though.
-
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 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.