Git diff:忽略以单词开头的行 [英] Git diff: ignore lines starting with a word
问题描述
正如我在此处所了解的那样,我们可以使用以下命令告诉git diff
忽略以*
开头的行:
As I have learned here, we can tell git diff
to ignore lines starting with a *
using:
git diff -G '^[[:space:]]*[^[:space:]*]'
如何告诉git忽略以一个单词或更多单词(例如:* Generated at
)开头的行,而不仅仅是一个字符?
How do I tell git to ignore lines starting with a word, or more (for example: * Generated at
), not just a character?
该文件将被忽略,它仅包含一些琐碎的更改:
This file shall be ignored, it contains only trivial changes:
- * Generated at 2018-11-21
+ * Generated at 2018-11-23
该文件不应被忽略,它不仅包含微不足道的更改:
This file shall NOT be ignored, it contains NOT only trivial changes:
- * Generated at 2018-11-21
+ * Generated at 2018-11-23
+ * This line is important! Although it starts with a *
推荐答案
Git正在使用 POSIX 似乎不支持环视的正则表达式.这就是 @Myys 3的方法不起作用的原因.一个不太优雅的解决方法可能是这样的:
Git is using POSIX regular expressions which seem not to support lookarounds. That is the reason why @Myys 3's approach does not work. A not so elegant workaround could be something like this:
git diff -G '^\s*([^\s*]|\*\s*[^\sG]|\*\sG[^e]|\*\sGe[^n]|\*\sGen[^e]|\*\sGene[^r]|\*\sGener[^a]|\*\sGenera[^t]|\*\sGenerat[^e]|\*\sGenerate[^d]).*'
这将过滤掉所有以"* Generated
"开头的更改.
This will filter out all changes starting with "* Generated
".
测试: https://regex101.com/r/kdv4V0/3
这篇关于Git diff:忽略以单词开头的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!