How to show line numbers by default with git grep command?
I know I can use the -n
flag in git grep
to show the line numbers of the results, i.e
git grep -n "some string"
but how could I include this flag by default without making an alias? I found git config --global grep.lineNumber true
but it doesn't seem to be working for me.
From the git grep manual:
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
I set my grep.lineNumber
using your command and it worked for me.
Have you considered using ack
? It's significantly more programmer friendly and comes in the repositories of most major linux distributions.
Under .gitconfig file
add this section
[grep]
linenumber = true
line number would be showed if you using git grep
The command you use
git config --global grep.lineNumber true
is the correct way to enable -n option by default.
But this feature is not available until v1.7.5-rc1. Check your local document for more information.
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