<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>diff &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/tag/diff/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Sat, 20 Jan 2024 17:24:55 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>[原创] MacOS下的那些diff工具</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-macos%e4%b8%8b%e7%9a%84%e9%82%a3%e4%ba%9bdiff%e5%b7%a5%e5%85%b7/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-macos%e4%b8%8b%e7%9a%84%e9%82%a3%e4%ba%9bdiff%e5%b7%a5%e5%85%b7/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sat, 20 Jan 2024 17:01:51 +0000</pubDate>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[colordiff]]></category>
		<category><![CDATA[diff]]></category>
		<category><![CDATA[grc]]></category>
		<category><![CDATA[icdiff]]></category>
		<category><![CDATA[MacOS]]></category>
		<category><![CDATA[meld]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=14003</guid>

					<description><![CDATA[<p>diff命令是最常用的、比较两个文本文件差异的工具。但在很多情况下，它并不那么好用，比如你想高亮显示差异的内容时，单纯的diff命令就做不到了。<br />
本文讨论了在macOS系统下，diff命令的一些&#8220;增强版&#8221;工具，让你用起来更方便。<br />
<span id="more-14003"></span><br />
<span style="color:#ff0000;">➤</span>&#160;安装、设置好 Homebrew 并保持最新<br />
在macOS里，为了方便快捷地安装各种软件包，首先你要装好Homebrew，具体过程这里不详述，可参考<a href="https://www.codelast.com/?p=14050" rel="noopener" target="_blank">这个</a>链接。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤</span>&#160;让 diff&#160;命令彩色化：通过&#160;grc&#160;配合<br />
单纯的 diff 命令本身并不直接提供高亮显示差异内容的功能。diff 命令通常输出两个文件之间的差异，包括新增的行、删除的行以及修改的行，但它使用的是标准的文本输出，没有颜色高亮。<br />
为了让 diff 命令输出彩色的内容，可以安装 grc（Generic Colouriser）软件：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="bash language-bash hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">brew&#160;install&#160;grc
</code></pre>
</section>
<p>安装完成后，修改 ~/.bash_profile&#160;文件，添加一行：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="bash language-bash hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-built_in" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">alias</span>&#160;diff=<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;/usr/local/bin/grc&#160;/usr/bin/diff&#39;</span></code></pre>
</section>
<p>然后重新打开终端，再用 <span style="color:#ff0000;">diff file1 file2</span>&#160;命令试一下，大概会是下面这样的效果：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="grc with diff" src="https://www.codelast.com/wp-content/uploads/2024/01/mac_os_diff_tool_1_grc_with_diff.png" style="width: 800px; height: 274px;" /></a><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤</span>&#160;colordiff&#160;软件：直接输出彩色的diff<br />
嫌上面安装&#160;grc&#160;的方法烦？可以直接安装&#160;colordiff&#160;软件：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="bash language-bash hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">brew&#160;install&#160;colordiff
</code></pre>
</section>
<p>再用 <span style="color:#ff0000;">colordiff file1 file2</span>&#160;命令来显示diff，大概会是下面这样的效果：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="colordiff" src="https://www.codelast.com/wp-content/uploads/2024/01/mac_os_diff_tool_2_colordiff.png" style="width: 800px; height: 273px;" /></a><br />
可以看到这个效果和 grc + diff&#160;差不多，所以考虑到简单，直接用colordiff就好了。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-macos%e4%b8%8b%e7%9a%84%e9%82%a3%e4%ba%9bdiff%e5%b7%a5%e5%85%b7/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>diff命令是最常用的、比较两个文本文件差异的工具。但在很多情况下，它并不那么好用，比如你想高亮显示差异的内容时，单纯的diff命令就做不到了。<br />
本文讨论了在macOS系统下，diff命令的一些&ldquo;增强版&rdquo;工具，让你用起来更方便。<br />
<span id="more-14003"></span><br />
<span style="color:#ff0000;">➤</span>&nbsp;安装、设置好 Homebrew 并保持最新<br />
在macOS里，为了方便快捷地安装各种软件包，首先你要装好Homebrew，具体过程这里不详述，可参考<a href="https://www.codelast.com/?p=14050" rel="noopener" target="_blank">这个</a>链接。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;让 diff&nbsp;命令彩色化：通过&nbsp;grc&nbsp;配合<br />
单纯的 diff 命令本身并不直接提供高亮显示差异内容的功能。diff 命令通常输出两个文件之间的差异，包括新增的行、删除的行以及修改的行，但它使用的是标准的文本输出，没有颜色高亮。<br />
为了让 diff 命令输出彩色的内容，可以安装 grc（Generic Colouriser）软件：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="bash language-bash hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">brew&nbsp;install&nbsp;grc
</code></pre>
</section>
<p>安装完成后，修改 ~/.bash_profile&nbsp;文件，添加一行：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="bash language-bash hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-built_in" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">alias</span>&nbsp;diff=<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;/usr/local/bin/grc&nbsp;/usr/bin/diff&#39;</span></code></pre>
</section>
<p>然后重新打开终端，再用 <span style="color:#ff0000;">diff file1 file2</span>&nbsp;命令试一下，大概会是下面这样的效果：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="grc with diff" src="https://www.codelast.com/wp-content/uploads/2024/01/mac_os_diff_tool_1_grc_with_diff.png" style="width: 800px; height: 274px;" /></a><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;colordiff&nbsp;软件：直接输出彩色的diff<br />
嫌上面安装&nbsp;grc&nbsp;的方法烦？可以直接安装&nbsp;colordiff&nbsp;软件：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="bash language-bash hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">brew&nbsp;install&nbsp;colordiff
</code></pre>
</section>
<p>再用 <span style="color:#ff0000;">colordiff file1 file2</span>&nbsp;命令来显示diff，大概会是下面这样的效果：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="colordiff" src="https://www.codelast.com/wp-content/uploads/2024/01/mac_os_diff_tool_2_colordiff.png" style="width: 800px; height: 273px;" /></a><br />
可以看到这个效果和 grc + diff&nbsp;差不多，所以考虑到简单，直接用colordiff就好了。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;icdiff：左右双屏的diff对比工具，很直观<br />
上面的diff命令，都是上下形式来展示，我觉得看起来很难受。icdiff 软件可以改变这种情况。安装：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="bash language-bash hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">brew&nbsp;install&nbsp;icdiff
</code></pre>
</section>
<p>命令 <span style="color:#ff0000;">icdiff file1 file2</span>&nbsp;的效果如下：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="icdiff" src="https://www.codelast.com/wp-content/uploads/2024/01/mac_os_diff_tool_3_icdiff.png" style="width: 800px; height: 356px;" /></a><br />
看到没，不仅左右对照，而且还彩色高亮显示，超级直观！<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;vim -d：基于vim的左右双屏对比<br />
使用 <span style="color:#ff0000;">vim -d file1 file2</span>&nbsp;命令，就可以在vim中左右双屏展示差异了：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="vim -d" src="https://www.codelast.com/wp-content/uploads/2024/01/mac_os_diff_tool_5_vim.png" style="width: 800px; height: 385px;" /></a><br />
但是注意：当一行内容太长的时候，vim在diff模式下不会把内容自动换行显示，看起来很不方便，你可以用 <span style="color:#ff0000;">:set wrap</span>&nbsp;命令来开启自动换行。<br />
如果要让光标在左右屏之间切换，按<span style="color:#ff0000;">两下</span>快捷键 <span style="color:#ff0000;">Ctrl+w</span>&nbsp;即可。<br />
缺点：当一行内容超长的时候，即使开启了自动换行，在一行内跳转也是极不方便的，而且鼠标又不能滚动文本，我觉得不爽。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;code --diff：基于VSCode的左右双屏对比<br />
什么？你天天使用的VSCode也能用做 diff&nbsp;工具？没错：<br />
<span style="color:#ff0000;">code --diff file1 file2</span><br />
这样就能在VSCode编辑器里展示出两个文件的 diff&nbsp;啦：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="VSCode diff" src="https://www.codelast.com/wp-content/uploads/2024/01/mac_os_diff_tool_6_vscode.png" style="width: 800px; height: 434px;" /></a><br />
如果你想修改diff显示的颜色，你甚至可以修改VSCode的配置(settings.json)来实现：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="json language-json hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;workbench.colorCustomizations&quot;</span>:&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&quot;diffEditor.insertedTextBackground&quot;</span>:&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;#fc00ce7c&quot;</span>,
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&quot;diffEditor.removedTextBackground&quot;</span>:&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;#4542f97c&quot;</span>,
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&quot;diffEditor.insertedLineBackground&quot;</span>:&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;#d9f4db66&quot;</span>,
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&quot;diffEditor.removedLineBackground&quot;</span>:&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;#e6dbe066&quot;</span>,
}
</code></pre>
</section>
<p>在这个例子中，workbench.colorCustomizations&nbsp;里的配置都是我添加的。<br />
diffEditor.insertedTextBackground&nbsp;配置的是 file1&nbsp;里的diff内容的颜色；<br />
diffEditor.removedTextBackground&nbsp;配置的是 file2&nbsp;里的diff内容的颜色；<br />
diffEditor.insertedLineBackground&nbsp;配置的是 file1&nbsp;里的diff行的背景色；<br />
diffEditor.removedLineBackground&nbsp;配置的是 file2&nbsp;里的diff行的背景色。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;Meld：图形化的双屏/三屏diff对比工具<br />
MacOS下的<a href="https://yousseb.github.io/meld/" rel="noopener" target="_blank">Meld</a>是另一个图形化diff工具。这个软件类似于Linux下的 meld&nbsp;软件，它不仅可以对比两个文件的 diff，还可以对比三个文件的diff。<br />
不过我在M2 CPU的MacOS上用起来，时不时会crash一次，所以就不想再用了。<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="Meld" src="https://www.codelast.com/wp-content/uploads/2024/01/mac_os_diff_tool_4_meld.png" style="width: 800px; height: 429px;" /></a><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;超长文本行的diff高亮显示<br />
上面提到的命令行的diff工具，在遇到超长文本行+某些内容的时候，在显示diff的时候都有这样那样的问题。<br />
例如，file1 的第一行和 file2 的第一行都有一万个字符，但它们仅仅在其中的5个字符有差异，那么diff工具理论上应该高亮显示出那5个字符。<br />
但实际上，当这行的内容有些特殊的时候，命令行diff工具可能会高亮显示出整行，而不是那5个字符；或者高亮显示的是多于那5个字符的一块区域。总之它有可能没法精确地标识出diff的部分。<br />
这里举一个例子：<br />
1.txt 和 2.txt 的第一行都超长，它们只在几个字符上有差异：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="VSCode diff long line" src="https://www.codelast.com/wp-content/uploads/2024/01/mac_os_diff_tool_7_vscode_deal_with_long_line.png" style="width: 800px; height: 44px;" /></a><br />
可见VSCode正确地只高亮了有差异的部分。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
如果用 icdiff 1.txt 2.txt 来查看差异，就非常扯蛋了，它没能像VSCode一样仅标识出diff的部分，而是把整行都标识成了diff，辣眼睛：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="icdiff deal with long line" src="https://www.codelast.com/wp-content/uploads/2024/01/mac_os_diff_tool_8_icdiff_deal_with_long_line.png" style="width: 800px; height: 322px;" /></a></p>
<p>在这种情况下，VSCode和Meld都可以正确标识出diff的内容。<br />
所以图形化diff工具还是有用的，别只迷信命令行。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：<br />
<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-macos%e4%b8%8b%e7%9a%84%e9%82%a3%e4%ba%9bdiff%e5%b7%a5%e5%85%b7/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
