在我的终端中彩色并排内联git diff输出 [英] Colored, side by side, inline git diff output in my terminal
问题描述
请注意,此问题不是重复的问题,而是问题的后续操作.这个问题寻求新的信息和解决问题的方法.
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.
另外,请注意,我仅在终端中寻找输出为内联的解决方案,例如默认的git diff
是-我不需要任何可打开外部gui diff程序的解决方案.
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.
我遵循了上面链接的SO问题的建议,并将以下可执行文件放在我的路径上:
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
我将得到这样的输出:
按预期,这是:
- 在终端中内联
- 并排输出
但是,它有几个问题:
- 如果更改了多个文件,它将在处理第一个文件后死亡,并输出错误
fatal: external diff died, stopping at <filename>
- 输出不使用绿色/红色来显示新代码/删除内容.
是否有一种方法可以解决sdiff
的这两个问题?如果不是,是否可以使用/usr/bin/diff
,内置的git diff程序或其他终端程序来执行此操作?我不在乎我如何实现目标.我只想要内嵌的并排差异与颜色.
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.
推荐答案
[THIS] worked fine for me, even with colors. (Thanks @ github.com/cockroachdb/cockroach)
如果您的终端在显示sdiff颜色时遇到问题,您可能希望将 sdiff 输送到 colordiff ,例如:
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 ...
这篇关于在我的终端中彩色并排内联git diff输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!