Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Git diff:仅显示与模式不匹配的更改_Regex_Git_Git Diff - Fatal编程技术网

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应用于差异而不是行,因此与重要更改相邻的不重要更改(通常)不会被过滤掉。