据我所知here ,我们可以告诉 git diff
忽略以 *
开头的行,使用:
git diff -G '^[[:space:]]*[^[:space:]*]'
我如何告诉 git 忽略以一个或更多(例如:* Generated at
)开头的行,而不仅仅是一个字符?
这个文件应该被忽略,它只包含微不足道的变化:
- * Generated at 2018-11-21
+ * Generated at 2018-11-23
不应忽略此文件,它不仅包含琐碎的更改:
- * Generated at 2018-11-21
+ * Generated at 2018-11-23
+ * This line is important! Although it starts with a *
最佳答案
Git 正在使用 POSIX似乎不支持 lookarounds 的正则表达式.这就是为什么 @Myys 3's approach 的原因不起作用。一个不太优雅的解决方法可能是这样的:
git diff -G '^\s*([^\s*]|\*\s*[^\sG]|\*\sG[^e]|\*\sGe[^n]|\*\sGen[^e]|\*\sGene[^r]|\*\sGener[^a]|\*\sGenera[^t]|\*\sGenerat[^e]|\*\sGenerate[^d]).*'
这将过滤掉所有以“* Generated
”开头的更改。
关于regex - Git 差异 : ignore lines starting with a word,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53451455/