如何使用 git grep 命令默认显示行号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11107059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show line numbers by default with git grep command?
提问by jfisk
I know i can use the -n flag in git grep to show the line numbers of the results, i.e
我知道我可以在 git grep 中使用 -n 标志来显示结果的行号,即
git grep -n "some string"
but how could i include this flag by default without resulting to making an alias? I found git config --global grep.lineNumber true
but it doesnt seem to be working for me.
但是如何在默认情况下包含此标志而不导致创建别名?我找到了,git config --global grep.lineNumber true
但它似乎对我不起作用。
采纳答案by jfisk
回答by ThorSummoner
From the git grep manual:
从 git grep 手册:
Options:
-n, --line-number
Prefix the line number to matching lines.
Configuration:
grep.lineNumber
If set to true, enable -n option by default.
To turn on globally: git config --global grep.lineNumber true
全局开启: git config --global grep.lineNumber true
回答by Kit Ho
Under .gitconfig file
在 .gitconfig 文件下
add this section
添加此部分
[grep]
linenumber = true
line number would be showed if you using git grep
如果您使用 git grep,将显示行号
回答by Even Young
The command you use
你使用的命令
git config --global grep.lineNumber true
is the correct way to enable -n option by default.
是默认启用 -n 选项的正确方法。
But this feature is not available until v1.7.5-rc1. Check your local document for more information.
但是这个功能直到 v1.7.5-rc1 才可用。查看您当地的文件以获取更多信息。
git grep --help
Also if you are interested, here is the commit introduced this feature:
另外,如果您有兴趣,这里是介绍此功能的提交:
grep: allow -E and -n to be turned on by default via configuration