<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>diff on
A Scripter's Notes</title><link>https://scripter.co/tags/diff/</link><description>Recent content in diff
on A Scripter's Notes</description><language>en-us</language><managingEditor>kaushal.modi@gmail.com (Kaushal Modi)</managingEditor><webMaster>kaushal.modi@gmail.com (Kaushal Modi)</webMaster><lastBuildDate>Wed, 22 Apr 2026 08:24:58 -0400</lastBuildDate><generator>Hugo -- gohugo.io</generator><docs>https://validator.w3.org/feed/docs/rss2.html</docs><atom:link href="https://scripter.co/tags/diff/index.xml" rel="self" type="application/rss+xml"/><item><title>Using Git Delta with Magit</title><link>https://scripter.co/using-git-delta-with-magit/</link><description>&lt;blockquote>&lt;em>Git Delta&lt;/em> is a command line utility that beautifies git diffs in the
terminal. But did you know that it can do the same in Magit too?&lt;/blockquote>&lt;div class="ox-hugo-toc toc">
&lt;div class="heading">Table of Contents&lt;/div>
&lt;ul>
&lt;li>&lt;a href="#installing-delta">Installing &lt;code>delta&lt;/code>&lt;/a>&lt;/li>
&lt;li>&lt;a href="#installing-magit-delta">Installing &lt;code>magit-delta&lt;/code>&lt;/a>&lt;/li>
&lt;li>&lt;a href="#configuring-delta">Configuring &lt;code>delta&lt;/code>&lt;/a>&lt;/li>
&lt;/ul>
&lt;/div>
&lt;!--endtoc-->
&lt;p>&lt;a href="https://github.com/dandavison/delta">Delta&lt;/a> is a highly configurable
&lt;span class="sidenote-number">&lt;small class="sidenote">
I am not kidding. Check out the output of &lt;a href="https://dandavison.github.io/delta/full---help-output.html">&lt;code>delta --help&lt;/code>&lt;/a>.
&lt;/small>&lt;/span>
command line utility that makes the git diffs look better, while also
syntax-highlighting
&lt;span class="sidenote-number">&lt;small class="sidenote">
&lt;a href="https://github.com/Wilfred/difftastic/">Difftastic&lt;/a> is another popular diff tool which compares files based on
their syntax. I like reviewing &lt;em>git diffs&lt;/em> from within Emacs
(Magit). But &lt;em>difftastic&lt;/em> &lt;a href="https://github.com/Wilfred/difftastic/issues/251">does not support Magit&lt;/a>.
&lt;/small>&lt;/span>
the code in the diffs.&lt;/p>
&lt;p>When I first heard of &amp;ldquo;syntax highlighted diffs&amp;rdquo;, I wasn&amp;rsquo;t sure what
that meant. If you are in the same boat, here&amp;rsquo;s a screenshot that
shows that.&lt;/p>
&lt;p>&lt;a id="figure--git-delta-example">&lt;/a>&lt;/p>
&lt;figure>
&lt;a href="delta-example.png">
&lt;img src="https://scripter.co/using-git-delta-with-magit/delta-example.png" alt="Figure 1: Example of how delta renders a git diff for an ox-hugo commit"/> &lt;/a>&lt;figcaption>
&lt;p>
&lt;span class="figure-number">Figure 1: &lt;/span>Example of how &lt;code>delta&lt;/code> renders a &lt;em>git diff&lt;/em> for an &lt;code>ox-hugo&lt;/code> commit
&lt;/p>
&lt;/figcaption>&lt;/figure>
&lt;p>But I do most of my git operations including viewing of diffs from
within Emacs, using &lt;a href="https://magit.vc">Magit&lt;/a>.&lt;/p>
&lt;div class="verse">
&lt;p>        .. and thankfully &lt;em>delta&lt;/em> &lt;a href="https://dandavison.github.io/delta/using-delta-with-magit.html">works with Magit&lt;/a>!&lt;br />&lt;/p>
&lt;/div>
&lt;p>Below screenshot shows how the same diff looks like in Magit.&lt;/p>
&lt;p>&lt;a id="figure--git-magit-delta-example">&lt;/a>&lt;/p>
&lt;figure>
&lt;a href="magit-delta-example.png">
&lt;img src="https://scripter.co/using-git-delta-with-magit/magit-delta-example.png" alt="Figure 2: Example of how magit-delta renders a git diff for an ox-hugo commit"/> &lt;/a>&lt;figcaption>
&lt;p>
&lt;span class="figure-number">Figure 2: &lt;/span>Example of how &lt;code>magit-delta&lt;/code> renders a &lt;em>git diff&lt;/em> for an &lt;code>ox-hugo&lt;/code> commit
&lt;/p>
&lt;/figcaption>&lt;/figure>
&lt;p>The &lt;a href="https://github.com/dandavison/magit-delta">&lt;code>magit-delta&lt;/code>&lt;/a> Emacs package makes this possible, which is also
developed by the &lt;code>delta&lt;/code> author Dan Davison.&lt;/p>
&lt;dl>
&lt;dt>Caveat&lt;/dt>
&lt;dd>If the line numbers are enabled in &lt;code>delta&lt;/code>, they mess up
the interactive expanding and collapsing of diffs in Magit. See
&lt;a href="https://github.com/dandavison/magit-delta/issues/13#issuecomment-949820122">Magit Delta Issue # 13&lt;/a> for more details.&lt;/dd>
&lt;/dl>
&lt;p>Now, I am alright with not seeing the line numbers in Magit. But I
really liked to see the line numbers in the side-by-side view in the
terminal. Luckily, if disabled the &lt;code>line-numbers&lt;/code> feature but enabled
the &lt;code>side-by-side&lt;/code> view, I got what I wanted!&lt;/p>
&lt;ol>
&lt;li>Line numbers are disabled in Magit and expanding/collapsing of
diffs works correctly. &lt;em>I am also really glad that I don&amp;rsquo;t see the
side-by-side view in Magit diffs even when I enable that feature in
&lt;code>delta&lt;/code>, because I like to have my Emacs buffers only about 90
characters wide.&lt;/em>&lt;/li>
&lt;li>Line numbers &lt;strong>and&lt;/strong> side-by-side view are enabled in the terminal.&lt;/li>
&lt;/ol>
&lt;p>I&amp;rsquo;ll end this post with pointers to installing &lt;code>delta&lt;/code> and
&lt;code>magit-delta&lt;/code> and how to configure them.&lt;/p>
&lt;h2 id="installing-delta">Installing &lt;code>delta&lt;/code>&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#installing-delta">#&lt;/a>&lt;/h2>
&lt;p>You can install &lt;code>delta&lt;/code> (it&amp;rsquo;s called &lt;code>git-delta&lt;/code> in some package
managers) using one of the methods listed &lt;a href="https://dandavison.github.io/delta/installation.html">in its manual&lt;/a>, or you can
download → extract its statically compiled binary for your OS from its
&lt;a href="https://github.com/dandavison/delta/releases">GitHub Releases&lt;/a> page.&lt;/p>
&lt;h2 id="installing-magit-delta">Installing &lt;code>magit-delta&lt;/code>&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#installing-magit-delta">#&lt;/a>&lt;/h2>
&lt;p>Once you put this snippet in your Emacs config and evaluate it, it
will install this package and enable the &lt;code>magit-delta-mode&lt;/code> in the
Magit buffers.&lt;/p>
&lt;p>&lt;a id="code-snippet--enabling-magit-delta">&lt;/a>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-emacs-lisp" data-lang="emacs-lisp">&lt;span class="line">&lt;span class="cl">&lt;span class="p">(&lt;/span>&lt;span class="nb">use-package&lt;/span> &lt;span class="nv">magit-delta&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nb">:ensure&lt;/span> &lt;span class="no">t&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nb">:hook&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nv">magit-mode&lt;/span> &lt;span class="o">.&lt;/span> &lt;span class="nv">magit-delta-mode&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="src-block-caption">
&lt;span class="src-block-number">&lt;a href="#code-snippet--enabling-magit-delta">Code Snippet 1&lt;/a>:&lt;/span>
Installing and enabling &lt;code>magit-delta&lt;/code> using &lt;code>use-package&lt;/code>
&lt;/div>
&lt;h2 id="configuring-delta">Configuring &lt;code>delta&lt;/code>&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#configuring-delta">#&lt;/a>&lt;/h2>
&lt;p>Here&amp;rsquo;s a snippet for &lt;code>delta&lt;/code> configuration from my &lt;code>.gitconfig&lt;/code>. It&amp;rsquo;s
mostly the same as the one in &lt;em>delta&lt;/em>&amp;rsquo;s the &lt;a href="https://github.com/dandavison/delta#get-started">Getting Started&lt;/a> guide. The
main difference in my workaround for the &lt;code>magit-delta&lt;/code> issue.&lt;/p>
&lt;p>&lt;a id="code-snippet--delta-gitconfig">&lt;/a>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>core&lt;span class="o">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nv">pager&lt;/span> &lt;span class="o">=&lt;/span> delta
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>interactive&lt;span class="o">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nv">diffFilter&lt;/span> &lt;span class="o">=&lt;/span> delta --color-only
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>add.interactive&lt;span class="o">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nv">useBuiltin&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="nb">false&lt;/span> &lt;span class="c1"># required for git 2.37.0&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>diff&lt;span class="o">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nv">colorMoved&lt;/span> &lt;span class="o">=&lt;/span> default
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>delta&lt;span class="o">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># https://github.com/dandavison/magit-delta/issues/13&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># line-numbers = true # Don&amp;#39;t do this.. messes up diffs in magit&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">#&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> side-by-side &lt;span class="o">=&lt;/span> &lt;span class="nb">true&lt;/span> &lt;span class="c1"># Display a side-by-side diff view instead of the traditional view&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># navigate = true # Activate diff navigation: use n to jump forwards and N to jump backwards&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> relative-paths &lt;span class="o">=&lt;/span> &lt;span class="nb">true&lt;/span> &lt;span class="c1"># Output all file paths relative to the current directory&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> file-style &lt;span class="o">=&lt;/span> yellow
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> hunk-header-style &lt;span class="o">=&lt;/span> line-number syntax
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="src-block-caption">
&lt;span class="src-block-number">&lt;a href="#code-snippet--delta-gitconfig">Code Snippet 2&lt;/a>:&lt;/span>
My configuration for &lt;code>delta&lt;/code> in &lt;code>.gitconfig&lt;/code>
&lt;/div></description><author>Kaushal.Modi@fakeEmailToMakeValidatorHappy.com (Kaushal Modi)</author><category domain="https://scripter.co/categories/emacs">emacs</category><category domain="https://scripter.co/tags/git">git</category><category domain="https://scripter.co/tags/100daystooffload">100DaysToOffload</category><category domain="https://scripter.co/tags/magit">magit</category><category domain="https://scripter.co/tags/diff">diff</category><guid>https://scripter.co/using-git-delta-with-magit/</guid><pubDate>Wed, 06 Jul 2022 22:04:00 -0400</pubDate></item><item><title>Git diff Minified JS and CSS</title><link>https://scripter.co/git-diff-minified-js-and-css/</link><description>&lt;blockquote>Make the &lt;code>git diff&lt;/code> output be more useful when diffing minified &lt;em>.js&lt;/em>
and &lt;em>.css&lt;/em> files.&lt;/blockquote>&lt;div class="ox-hugo-toc toc has-section-numbers">
&lt;div class="heading">Table of Contents&lt;/div>
&lt;ul>
&lt;li>&lt;span class="section-num">1&lt;/span> &lt;a href="#install-js-beautify-using-npm">Install &lt;code>js-beautify&lt;/code> using &lt;code>npm&lt;/code>&lt;/a>&lt;/li>
&lt;li>&lt;span class="section-num">2&lt;/span> &lt;a href="#configure-git-to-use-that-tool">Configure &lt;code>git&lt;/code> to use that tool&lt;/a>&lt;/li>
&lt;li>&lt;span class="section-num">3&lt;/span> &lt;a href="#add-update-dot-gitattributes-file-to-the-project-repo">Add/update &lt;code>.gitattributes&lt;/code> file to the project repo&lt;/a>&lt;/li>
&lt;li>&lt;a href="#beautiful-result">Beautiful Result&lt;/a>&lt;/li>
&lt;/ul>
&lt;/div>
&lt;!--endtoc-->
&lt;p>While working on a &lt;a href="https://github.com/gohugoio/gohugoioTheme/pull/84">little PR for the Hugo doc site theme&lt;/a>, I learned
that if I needed to make changes to JS/CSS, I had to commit my changes
in both unminified and minified versions.&lt;/p>
&lt;p>I have a habit to always look at the diffs at the time of staging and
committing. So it felt very unnatural to commit a minified JS where
the diff would show just &lt;strong>one&lt;/strong> changed line with thousands of
characters of minified+uglified JS.&lt;/p>
&lt;p>So I started looking for solutions, and found &lt;a href="https://cweiske.de/tagebuch/git-diff-minified-js.htm">this post&lt;/a> by &lt;em>Christian
Weiske&lt;/em> where he suggests using &lt;a href="https://github.com/beautify-web/js-beautify">&lt;code>js-beautify&lt;/code>&lt;/a> to &lt;em>beautify&lt;/em> minified
JS diffs.&lt;/p>
&lt;div class="verse">
&lt;p>    &lt;em>And that tool works beautifully!&lt;/em>&lt;br />&lt;/p>
&lt;/div>
&lt;ul>
&lt;li>I later found out that the same tool can also be used to &lt;em>beautify&lt;/em>
minified CSS.&lt;/li>
&lt;li>.. and I installed that tool using &lt;code>npm&lt;/code> as the &lt;code>pip3&lt;/code> approach
failed with &lt;em>&amp;ldquo;Collecting js-beautify.. Could not find a version that
satisfies the requirement js-beautify (from versions: ) No matching
distribution found for js-beautify&amp;rdquo;&lt;/em>.&lt;/li>
&lt;/ul>
&lt;p>So here&amp;rsquo;s how you can do useful &lt;code>git diff&lt;/code> for minified JS and CSS.&lt;/p>
&lt;h2 id="install-js-beautify-using-npm">&lt;span class="section-num">1&lt;/span> Install &lt;code>js-beautify&lt;/code> using &lt;code>npm&lt;/code>&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#install-js-beautify-using-npm">#&lt;/a>&lt;/h2>
&lt;p>I see myself using &lt;code>js-beautify&lt;/code> in many other projects too. So I
installed it globally.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">npm install --global js-beautify
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;h2 id="configure-git-to-use-that-tool">&lt;span class="section-num">2&lt;/span> Configure &lt;code>git&lt;/code> to use that tool&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#configure-git-to-use-that-tool">#&lt;/a>&lt;/h2>
&lt;p>Add below to your &lt;code>~/.gitconfig&lt;/code>:&lt;/p>
&lt;ol>
&lt;li>Use &lt;code>js-beautify&lt;/code> to first beautify the minified JS for the &lt;code>minjs&lt;/code>
&lt;em>diff configuration&lt;/em>, and then do a diff of those beautified files.&lt;/li>
&lt;li>Enable caching of those beautified files to speed up the diff, so
that &lt;em>re-beautification&lt;/em> of unmodified minified files can be
skipped.&lt;/li>
&lt;li>Similarly for minified CSS, use &lt;code>js-beautify --css&lt;/code> to first
beautify the minified CSS for the &lt;code>mincss&lt;/code> &lt;em>diff configuration&lt;/em>.&lt;/li>
&lt;/ol>
&lt;!--listend-->
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-ini" data-lang="ini">&lt;span class="line">&lt;span class="cl">&lt;span class="k">[diff &amp;#34;minjs&amp;#34;]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="na">textconv&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s">js-beautify
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s"> cachetextconv = true&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">[diff &amp;#34;mincss&amp;#34;]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="na">textconv&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s">js-beautify --css
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s"> cachetextconv = true&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;h2 id="add-update-dot-gitattributes-file-to-the-project-repo">&lt;span class="section-num">3&lt;/span> Add/update &lt;code>.gitattributes&lt;/code> file to the project repo&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#add-update-dot-gitattributes-file-to-the-project-repo">#&lt;/a>&lt;/h2>
&lt;p>Now, in your project repo&amp;rsquo;s &lt;code>.gitattributes&lt;/code> file, you need to
associate files with the &lt;em>diff configurations&lt;/em> set above.&lt;/p>
&lt;p>Below will use the &lt;code>minjs&lt;/code> configuration for &lt;em>*.min.js&lt;/em> and
&lt;em>*.bundle.js&lt;/em> files, and &lt;code>mincss&lt;/code> configuration for &lt;em>*.min.css&lt;/em> and
&lt;em>main.css&lt;/em>.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-ini" data-lang="ini">&lt;span class="line">&lt;span class="cl">&lt;span class="na">*.min.js diff&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">minjs&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">*.bundle.js diff&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">minjs&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">*.min.css diff&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">mincss&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">main.css diff&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">mincss&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;h2 id="beautiful-result">Beautiful Result&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#beautiful-result">#&lt;/a>&lt;/h2>
&lt;p>&lt;a id="figure--git-diff-min-js">&lt;/a>&lt;/p>
&lt;figure>
&lt;img src="https://scripter.co/git-diff-minified-js-and-css/git-diff-minified-js.png" alt="Figure 1: git diff of minified JS as seen in Magit"/> &lt;figcaption>
&lt;p>
&lt;span class="figure-number">Figure 1: &lt;/span>&lt;code>git diff&lt;/code> of minified JS as seen in &lt;em>Magit&lt;/em>
&lt;/p>
&lt;/figcaption>&lt;/figure>
&lt;p>Isn&amp;rsquo;t that better than how GitHub shows the &lt;em>exact same commit
diff&lt;/em>? 😎&lt;/p>
&lt;p>&lt;a id="figure--github-diff-min-js">&lt;/a>&lt;/p>
&lt;figure>
&lt;img src="https://scripter.co/git-diff-minified-js-and-css/github-diff-minified-js.png" alt="Figure 2: Same commit diff shown on GitHub"/> &lt;figcaption>
&lt;p>
&lt;span class="figure-number">Figure 2: &lt;/span>Same commit &lt;code>diff&lt;/code> shown on &lt;em>GitHub&lt;/em>
&lt;/p>
&lt;/figcaption>&lt;/figure></description><author>Kaushal.Modi@fakeEmailToMakeValidatorHappy.com (Kaushal Modi)</author><category domain="https://scripter.co/categories/web">web</category><category domain="https://scripter.co/categories/unix">unix</category><category domain="https://scripter.co/tags/minified">minified</category><category domain="https://scripter.co/tags/javascript">javascript</category><category domain="https://scripter.co/tags/git">git</category><category domain="https://scripter.co/tags/diff">diff</category><category domain="https://scripter.co/tags/css">css</category><category domain="https://scripter.co/tags/magit">magit</category><guid>https://scripter.co/git-diff-minified-js-and-css/</guid><pubDate>Mon, 19 Mar 2018 18:13:00 -0400</pubDate></item></channel></rss>