如何提高git的差异突出显示? [英] How to improve git's diff highlighting?

查看:58
本文介绍了如何提高git的差异突出显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git diff的输出针对倾向于每行一个语句的代码进行了优化,而文本可能会(如果像我这样的作者懒于使用换行符)会导致diff输出,这很难理解,并且更多沃利在哪里?"搜索比读取差异输出

The output of git diff is optimized for code which tends to be one statement per line whereas text can (if authors like me are too lazy to use line breaks) cause diff output which is very hard to read and more of a "Where's Wally?" search than reading diff output

在GitLab或GitHub的Web前端上进行的突出显示会立即显示出差异

whereas highlighting as done on GitLab's or GitHub's web frontend shows the difference immediately

我知道我正在比较HTML和纯文本(苹果和橘子),但是应该可以通过使用不同的颜色或在更改周围添加标记字符来改善git diff输出(JUnit使用不太好读的插入法,但是我的意思是一个例子),这将是我第一次期望git中有些可用的东西,但实际上不是.

I'm aware that I'm comparing HTML and plain text (apples and oranges), however it should be possible to improve the git diff output by using different colors or adding marker characters around a change (JUnit uses [] around insertions which isn't great to read, but an example for what I mean) and it would be the first time that there's something I expect to be somewhere available in git that actually was not.

推荐答案

您可以使用--word-diff[=<mode>]选项使查看一行中的哪些单词发生更改变得更加容易.在手册页中将其描述为

You could use the --word-diff[=<mode>] option to make it easier to see which words have changed within a line. This is described in the man page as

显示单词差异,使用<mode>分隔更改的单词.默认情况下,单词以空格分隔;请参阅下面的--word-diff-regex. <mode>默认为纯文本,并且必须为以下其中之一:

Show a word diff, using the <mode> to delimit changed words. By default, words are delimited by whitespace; see --word-diff-regex below. The <mode> defaults to plain, and must be one of:

  • color –仅使用颜色突出显示更改的单词.表示--color.

  • color – Highlight changed words using only colors. Implies --color.

plain –将单词显示为[-removed-]{+added+}.,如果它们出现在输入中,则不尝试转义定界符,因此输出可能不明确.

plain – Show words as [-removed-] and {+added+}. Makes no attempts to escape the delimiters if they appear in the input, so the output may be ambiguous.

porcelain –使用特殊的基于行的格式供脚本使用.添加/删除/未更改的运行以通常的统一diff格式打印,从行开头的+/-/` `字符开始,一直扩展到行的末尾.输入中的换行符由波浪号~表示为一行.

porcelain – Use a special line-based format intended for script consumption. Added/removed/unchanged runs are printed in the usual unified diff format, starting with a +/-/` ` character at the beginning of the line and extending to the end of the line. Newlines in the input are represented by a tilde ~ on a line of its own.

none –再次禁用单词diff.

none – Disable word diff again.

请注意,尽管启用了第一种模式,但如果启用,颜色将用于突出显示所有模式中更改的部分.

Note that despite the name of the first mode, color is used to highlight the changed parts in all modes if enabled.

这篇关于如何提高git的差异突出显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆