【问题标题】:Git grep print only matching patternGit grep 仅打印匹配模式
【发布时间】:2019-08-02 17:28:54
【问题描述】:

grep 的手册中,我们有-o 打印--only-matching 模式。假设echo foobar | grep foo 将返回foobar,但将-o 添加到grep 只会得到foo

-P-c 等许多 grep 选项可以与 git 结合使用,以搜索 Git 索引中的所有文件。但是,git grep -o PAT 会触发 error: unknown switcho'`。

如何为 Git 索引中的每个文件只打印匹配的字符串?即“git grep -o PAT

我的审判:

for f in `git ls-files`; do grep -o PAT $f; done

【问题讨论】:

标签: git grep


【解决方案1】:

git grep 2.18 没有选项-o|--only-matchinggit grep 2.19 有。如果您的版本低于 2.19,则无法使用该选项。要使用它,您必须升级。

【讨论】:

    猜你喜欢
    • 2021-03-19
    • 2012-09-22
    • 2021-09-10
    • 2017-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-06
    相关资源
    最近更新 更多