command line recursive word-based diff?
Asked Answered
M

1

14

is there a command line program that gives recursive word-based diff (on 2 directories)?

diff -u is recursive, but it doesn't do word by word comparison. wdiff and dwdiff does word based diff but there are not built-in options for recursive diff.

I would like to pipe the result to colordiff so a program that generates output that colordiff understands would be especially useful. Any suggestions? Thanks!

CC

Myrtamyrtaceous answered 13/2, 2011 at 0:53 Comment(1)
This doesn't really answer your question (hence posting as a comment), but if you're on a system with a GUI then it might be easier to use a GUI diff program. I find meld (meld.sourceforge.net) to be quite good.Rocketeer
B
28

Git can do it and output color:

The following often works:

git diff --color-words path1 path2

but in general you may need to do

git diff --no-index --color-words path1 path2

Neither file even needs to be in a git repository!

--no-index is needed if you and the paths are in a git working tree. It can be elided if you or one of the files are outside a git working tree.

Manpage: https://git-scm.com/docs/git-diff/1.8.5 (and later...)

git diff --no-index [--options] [--] […​]

This form is to compare the given two paths on the filesystem. You can omit the --no-index option when running the command in a working tree controlled by Git and at least one of the paths points outside the working tree, or when running the command outside a working tree controlled by Git.

Bey answered 5/5, 2011 at 1:9 Comment(3)
+1 - I never knew you could use git diff on files outside a repo. Thanks.Spherulite
Great idea if both inputs are files, but what if one input is the output of a command? - isn't accepted as a directive to use stdin. I tried Bash process substitution (git diff --no-index -- <(echo foo quux baz) somefile), but apparently git-diff-file doesn't read from a named pipe but instead prints the "contents" as pipe:[3377923] or similar.Queasy
@Queasy If your commands take a file as input, you may be able to use textconv. For example, I wanted to run git diff ... <(gzip -dc foo.gz) <(gzip -dc bar.gz). I was able to achieve this by adding *.gz diff=gz to .gitattributes, adding [diff "gz"] ` textconv=gzip -dc` to .gitconfig, and running git diff --textconv ... foo.gz bar.gzSkylab

© 2022 - 2024 — McMap. All rights reserved.