Git diff:仅显示与模式不匹配的更改 [英] Git diff: show ONLY changes not matching a pattern

查看:104
本文介绍了Git diff:仅显示与模式不匹配的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以让git diff假定以某种模式凝视的线条没有改变?

Is it possible to tell git diff to assume lines staring with some pattern as unchanged?

例如,考虑以下内容:

$ 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更改.有可能吗?

Lines starting with an asterisk (regex pattern "^[[:space:]]*\*.*") are not important and I would like to filter files that contain changes in such lines only from the output of git diff. In the example above, the output should report file_b.txt changes only. Is it possible?

推荐答案

可以使用git diff -G标志并反转正则表达式以匹配行,即第一个非空格字符既不是*也不是空格.

It's possible with the git diff -G flag and making inverting the regexp to match lines that the first character that is not space is neither a * nor space.

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

效率不高,因为会回溯,但不支持负超前'^(?!\s*\*)',所有格修饰符'^\s*+[^*]'或原子组'^(?>\s*)[^*]'.

Not very efficient because will backtrack but seems negative lookahead '^(?!\s*\*)', possessive quantifier '^\s*+[^*]' or atomic groups '^(?>\s*)[^*]' are not supported.

这篇关于Git diff:仅显示与模式不匹配的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆