问题
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:
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:
[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 ...
来源:https://stackoverflow.com/questions/49685260/colored-side-by-side-inline-git-diff-output-in-my-terminal