6

Please note this question is not a duplicate of, but a followup to the question "How can I get a side-by-side diff when I do “git diff”?". This question seeks new information and the solution to a problem.

Also, please note that I am seeking only solutions whose output is inline in the terminal like the default git diff is -- I don't want anything which opens an external gui diff program.

Progress so far

I have followed the suggestion from the SO question linked above and put the following executable on my path:

#!/bin/bash

# side-by-side diff with custom options:
sdiff -w200 -l "$2" "$5" 

I can then test it like so, for example:

GIT_EXTERNAL_DIFF=mydiff git diff HEAD HEAD~1

and I'll get output like this:

Screenshot

The Problem

As intended, this is:

  • inline in the terminal
  • side by side output

However, it has a couple problems:

  • If more than one file has changed, it dies after processing the first file, outputting the error fatal: external diff died, stopping at <filename>
  • The output doesn't use green/red colors to show new code / deletions.

Is there a way to remedy those two issues with sdiff? If not, is there a way to do it with /usr/bin/diff, the built in git diff program, or another terminal program? I don't care how I accomplish the goal. I just want inline, side by side diffs with color.

1
  • If there is a way to do this from the terminal, it would be really cool. But as a workaround, do you have access to an IDE like IntelliJ? IntelliJ has a great diff tool which works well with Git. Commented Apr 6, 2018 at 4:29

1 Answer 1

4

[THIS] worked fine for me, even with colors. (Thanks @ github.com/cockroachdb/cockroach)

If your terminal has issues displaying colors with sdiff, you probably want to pipe sdiff to colordiff like:

sdiff -w200 -l "$2" "$5" | colordiff | grep -E ...
2
  • 1
    TYVM! Still have a couple minor issues after setting up icdiff. 1. Per my post, in my mydiff bash script I now have icdiff --unified=2 --line-numbers "$2" "$5" (the bash wrapper seems required to keep it inline). This works, however the file names in the icdiff output look weird, eg /var/folders/r5/tx39k3394y99z55mzn683ypr0000gn/T//iyhopb_authn_ldap.gemspec. Also, for more than a screenful of output, I have to press q when it finishes to get my prompt back. Any ideas for fixing those issues?
    – Jonah
    Commented Apr 6, 2018 at 12:17
  • 1
    Turns out icdiff --unified=2 --line-numbers -L "$1" -L "$1" "$2" "$5" solves the naming issue. And --no-pager would solve the q issue, but on second thought I don't think I actually want that, and it's default behavior for git-diff anyway
    – Jonah
    Commented Apr 6, 2018 at 13:53

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