Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Icdiff: Side-by-side highlighted command line diffs (jefftk.com)
112 points by stepstop on July 6, 2020 | hide | past | favorite | 43 comments


Another little known diff power tool:

    vim -d old.txt new.txt
This will open two files in diff mode. You can then use a whole host of fancy keybindings to edit the two files in a diff-aware way ("apply this hunk to that file" / manually edit a file and then re-render the diff / "fold or expand all non-hunk text" / etc.). For more:

    :help diff
or see here https://neovim.io/doc/user/diff.html


I am a big fan of the patchreview plugin, I use it every day. It opens a multifile diff (e.g. git diff patch output) each file in a vim tab.

https://github.com/junkblocker/patchreview-vim

$ gvim -c"DiffReview git diff origin/master"


Good shout. I've used that a fair few times when working through some more complex diffs.

It's also often symlinked as `vimdiff`


A similar tool that I really like is meld (https://meldmerge.org/). It has a GUI, really nice visual indicators, allows you to view the entire file and directory trees and you can jump between diff chunks using alt + arrow up/down.

I often use it with git:

git difftool -t meld -d


How is that similar? It's a GUI. There's a zillion GUI diff tools but very few console ones. icdiff is the only side by side CLI diff tools I have seen.


sdiff has been around forever:

https://linux.die.net/man/1/sdiff

It’s not a three-way diff and not highlighted however. (icdiff doesn’t seem to be a three-way diff either.)


Delta is a similar tool with syntax highlighting for most programming languages and customizable themes:

https://github.com/dandavison/delta

It doesn't have side-by-side diffs, but it's still well worth having around.

It's a Unix filter, so it works on any unified diff you can come up with.

Its default output isn't a unified diff, but that's easy to fix with its configuration / CLI options (I'm too used to reading unified diffs to like delta's simplified default format).


This looks nice, but is it very different from gnu(?) diff --color=always --side-by-side?


Could you share a screenshot? When I run GNU diff with --side-by-side, it seems that --color=always is ignored: https://www.jefftk.com/gnudiff-color-always-side-by-side.png



Thanks! After playing with diff --color=always --side-by-side more, it looks like it colors inserted and deleted lines but not changed lines: https://www.jefftk.com/icdiff-vs-diff-color-always-side-by-s...

(And it still doesn't find changes within a line)


I think, for changes within a line, wdiff would be the usual tool - but even if it's possible to pipe that through colordiff - I don't think there's a side-by-side mode for wdiff.

But yeah, I see that in-line highlighting of changes can be helpful sometimes :)


I've been using `alias diff=colordiff` for maybe twenty years. Looks like icdiff can highlight small changes without needing to call out the whole line. Is there anything else new this one brings?


Screenshots:

* colordiff -y: https://www.jefftk.com/colordiff-y-example-simple.png

* icdiff: https://www.jefftk.com/icdiff-example-simple.png

The two main differences I see are that icdiff can highlight the affected portions of lines, and that icdiff makes better use of horizontal space.


I see. Also, I'd configured colordiff to use green and red as well.


If you're used to Git's diff view and want to use it for any two files outside of a repo, you can do

    $ git diff --no-index file_a file_b


colordiff -y [https://www.colordiff.org/] has similar functionality.


Another alternative: Kitty-diff

It’s terminal specific as it uses kitty’s graphics extensions but it looks really IMHO.

https://sw.kovidgoyal.net/kitty/kittens/diff.html


colordiff highlights the entire line when any part is changed:

* colordiff -y: https://www.jefftk.com/colordiff-y-example-simple.png

* icdiff: https://www.jefftk.com/icdiff-example-simple.png

icdiff also makes better use of horizontal space.


This is a really useful utility. This post explains how to use it with mercurial for better diffs:

https://ianobermiller.com/blog/2016/07/14/side-by-side-diffs...


I like diffoscope's side-by-side HTML diffs of arbitrary files/dirs, for eg:

https://diffoscope.org/ https://diffoscope.org/examples/https-everywhere-5.0.6_vs_5....


I wish Icdiff had syntax highlighting for common programming languages.


I'd be happy to review a PR! https://github.com/jeffkaufman/icdiff


Wouldn't the syntax coloring interfere with the diff coloring? Is there an example of a tool that does both?


At least one of the other tools in this thread does both. (Rather than visualising add/rm with the foreground, it's visualised with the background colour). https://github.com/dandavison/delta


Yes, but delta doesn't have side-by-side diff. Is someone aware of a command line util, that has side-by-side diff and syntax highlighting? I know that Gitlab can do that.


Looks like delta has an open issue: https://github.com/dandavison/delta/issues/86


vimdiff does that.


True, but vimdiff is a wrapper around vim, that starts the editor with pre-arranged windows. I would like to have a non-interactive stand-alone tool, that prints the syntax highlighted side-by-side to the terminal then exits and does not require you to learn vim. Maybe such a thing does not exist yet and I have to wait for delta issue #86 to happen.


Agree with this point. If your diff is so large you need syntax highlighting to make sense of it maybe you should step back and evaluate your version control habits. A diff tool should focus on what changed and nothing else.


Related: diff2html CLI that will open your browser to a beautifully-rendered HTML diff:

https://diff2html.xyz/


ydiff might be the tool you're looking for.

https://github.com/ymattw/ydiff


Ydiff is GIT aware. It made me :) recently when I needed to diff a 6 month branch divergence.


In your experience, What's the best tool to check 3-way merge diffs under windows?


Both emacs and vim can be run under windows, and both have the ability to display 3-way merges quite well.

For emacs, you'd want magit + smerge or ediff.

In vim, you'd want vimdiff + vim-fugitive for a few handy helpers.


I use CLion (or other Jetbrains IDEs, eg PyCharms on the occasions I'm not working in C/C++/Rust). They've got a very nice built-in 3-way merge diff tool. Non-free for some of the IDEs, but if you're working with a language that has a free "community edition" this is viable. Or if you're willing to pay for a very nice IDE.


I’ll get shot down for it, but I love the JetBrains IDE visual merge tool. It’s not free, but this among other things makes it worth it for professional work.


Not free, but Araxis Merge is pretty good.


> 3-way merge diffs under windows

Is there any reason for not using kdiff3?


Yet another option: p4merge (from Perforce) works great.


Meld is pretty neat


Beyond Compare


It really does live up to it's name in my opinion. Been using it for over a decade, originally in Windows but now macOS




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: