Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to diff two files (not two versions of the same file, they are however tracked by git, but that is unrelated) and I would like some colored output, how can I achieve that?

$ diff file_1 file_2

1,9d0
< <script ... >
<     // more code
< </script>

$ 

That gives me all differences, however without any colors. For longer diffs that is hard to read.


Alternatively, is there a way for git (with which I do have nice color output) to diff two different files (not changes to a file)?

OSX (10.7.5)

share|improve this question
add comment

3 Answers

up vote 11 down vote accepted

Perl has a a lackluster colordiff wrapper for diff, but I prefer grc (generic colorizer).

With grc (generic colorizer), you can write your own wrappers for different types of commands or inputs (if you like that sort of thing).

Below, grc is running against /var/log/syslog (in the config, this file is set to a certain color scheme), where it highlights processes, pids, IPs and "connect"s.

Of course, it is recommended to use an alias so you don't forget:

alias diff=`/usr/bin/grc /usr/bin/diff`

grc running against syslog


If you have git, you may just want to use that, which allows very robust diffing, even across branches.

git diff master:cogs/foo.txt branch:widgets/bar.txt

You do not have to use git diff within a repository, you can use it for just regular files.

git diff old.txt new.txt

As always, you can alias diff for ease of use.

alias diff=`git diff`
share|improve this answer
add comment

When diffing files I almost always use vim:

vim -d file_1 file_2

It not only uses colours, it lines up the files so it's easier to see lines added/removed.

share|improve this answer
add comment

You can get git to diff two different files:

git diff branch1:full/path/to/foo.txt branch2:full/path/to/foo-another.txt
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.