1

in a normal git diff, output may look like this:

diff --git a/app/index.html b/app/index.html
index f1a34ce..723dc5c 100644
--- a/app/index.html
+++ b/app/index.html
@@ -9,6 +9,7 @@
 
     {{content-for "head"}}
 
+    <link integrity="" rel="stylesheet" href="{{rootURL}}assets/tailwind.css">
     <link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
     <link integrity="" rel="stylesheet" href="{{rootURL}}assets/my-app.css">
 

is there a way to omit this:

index f1a34ce..723dc5c 100644
--- a/app/index.html
+++ b/app/index.html
@@ -9,6 +9,7 @@

So that all that's left is:

diff --git a/app/index.html b/app/index.html
 
     {{content-for "head"}}
 
+    <link integrity="" rel="stylesheet" href="{{rootURL}}assets/tailwind.css">
     <link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
     <link integrity="" rel="stylesheet" href="{{rootURL}}assets/my-app.css">
 

This is the best I've been able to come up with:

git diff \
  | sed -n '/^---/!p' \
  | sed -n '/^+++/!p' \
  | sed -n '/^@@/!p'  \
  | sed -n '/^index /!p'

But there has to be a better way?

NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352
  • You could write an alias that would find those lines by pattern and remove them. Would that do? (You'd need to believe there's a regular expression that would express the pattern, and you'd need to accept the use of an alias rather than seeking some sort of built-in `diff` modifier.) – matt Jan 22 '22 at 23:10
  • yeah, just hoping there'd be something built in to git somewhere – NullVoxPopuli Jan 22 '22 at 23:12
  • I don't think there is. :) But the alias makes the notion of piping thru sed a lot less unpleasant. See my question here: https://stackoverflow.com/questions/70685295/git-diff-dictate-extra-blank-line-between-files – matt Jan 22 '22 at 23:39
  • There's a shorter one, though. `git diff | sed '/^diff/,/^@@/ {/^diff/!d}'` – jthill Jan 23 '22 at 00:32

1 Answers1

0

You could set the GIT_EXTERNAL_DIFF environment variable when calling git diff, as explained in git(1):

When the environment variable GIT_EXTERNAL_DIFF is set, the program named by it is called to generate diffs, and Git does not use its builtin diff machinery. For a path that is added, removed, or modified, GIT_EXTERNAL_DIFF is called with 7 parameters:

path old-file old-hex old-mode new-file new-hex new-mode

Write a small shell-script that starts your favorite diff between old-file and new-file and ignores the other arguments.

Roland Smith
  • 42,427
  • 3
  • 64
  • 94