【问题标题】:Is it possible to git grep for tabs?是否可以 git grep 用于选项卡?
【发布时间】:2011-05-14 19:29:33
【问题描述】:

This question 指定-P 允许 GNU grep 来 grep 选项卡

grep -P '\t' config/file.txt

但是,使用git grep,我不知道如何用 grep 查找选项卡:

git grep '\t' # Looks for files with the letter "t" instead
git grep -P '\t' # Invalid option
git grep -E '\t' # Does the same as without the -E

而且似乎没有替代您自己的grep 程序的选项。我唯一的选择是吞下整个内容然后在结果上使用 GNU grep 吗?

【问题讨论】:

标签: git grep


【解决方案1】:

您可以通过在命令中键入文字选项卡来解决此问题:

# type it with ^V then tab
git grep '  '

【讨论】:

  • :D 好吧,是的。 ctrl-v 的 Bash 是什么意思?
  • @three: 不清楚?就像我说的,如果你输入 ^V 然后制表符,你会得到一个文字制表符。它逐字(字面意思)解释下一个击键,而不是对其进行特殊解释。
【解决方案2】:

我找不到可以工作的选项卡的正则表达式符号,但如果你可以传入一个文本选项卡,它会很高兴地搜索一个文本选项卡。在 bash 中,那将是

git grep $'\t'

【讨论】:

  • 这种语法也适用于 grepping 回车:git grep $'\r'
  • 如果您需要进行更具体的搜索,例如使用正则表达式匹配行首,那么您也可以执行 git grep '^'$'\t\t'
【解决方案3】:

在 Windows 上,以下在 PowerShell 中有效:

git grep "`t"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 2021-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多