Regex Git diff:仅显示与模式不匹配的更改
有没有可能告诉Regex Git diff:仅显示与模式不匹配的更改,regex,git,git-diff,Regex,Git,Git Diff,有没有可能告诉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 i
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
以星号开头的行(regex pattern
“^[[:space:]*\*.*”
)并不重要,我只想从git diff
的输出中筛选包含此类行更改的文件。在上面的示例中,输出应该只报告文件_b.txt
更改。有可能吗?有可能使用git diff-G
标志并反转regexp以匹配行,第一个不是空格的字符既不是*
也不是空格
-G '^[[:space:]]*[^[:space:]*]'
不是很有效,因为不支持回溯,但似乎是负前瞻的
'^(?!\s*\*')
、所有格量词'^\s*+[^*]'
或原子组'^(?>\s*)[^*]'
。这可能是最好的方法,但要注意其局限性。grep应用于差异而不是行,因此与重要更改相邻的不重要更改(通常)不会被过滤掉。