Git diff:仅显示不匹配模式的更改

Git diff: show ONLY changes not matching a pattern

是否可以告诉 git diff 假设以某种模式开始的行没有变化?

例如,考虑以下内容:

$ git diff -U0
diff --git a/file_a.txt b/file_a.txt
index 26ed843..4071ff8 100644
--- a/file_a.txt
+++ b/file_a.txt
@@ -24 +24 @@
- * unimportant foo
+ * unimportant bar
diff --git a/file_b.txt b/file_b.txt
index c6d051e..4b3cf22 100644
--- a/file_b.txt
+++ b/file_b.txt
@@ -24 +24 @@
- * unimportant foo
+ * unimportant bar
@@ -48,0 +49 @@
+   this is important  
@@ -56,0 +58 @@
+   this is also important

以星号(正则表达式模式 "^[[:space:]]*\*.*")开头的行并不重要,我只想从 git diff 的输出中过滤包含此类行更改的文件。在上面的示例中,输出应仅报告 file_b.txt 更改。可能吗?

可以使用 git diff -G 标志并反转正则表达式以匹配第一个不是 space 的字符既不是 * 也不是 space 的行。

-G '^[[:space:]]*[^[:space:]*]'

不是很有效,因为会回溯,但似乎是负面的前瞻性 '^(?!\s*\*)',不支持所有格量​​词 '^\s*+[^*]' 或原子组 '^(?>\s*)[^*]'