Git diff: show ONLY changes not matching a pattern

北战南征 提交于 2019-12-11 02:59:56

问题


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

For example, consider the following:

$ 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

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?


回答1:


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:]*]'

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



来源:https://stackoverflow.com/questions/53450186/git-diff-show-only-changes-not-matching-a-pattern

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!