Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show line numbers by default with git grep command?

Tags:

git

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.

like image 362
jfisk Avatar asked Jun 19 '12 18:06

jfisk


People also ask

How do I show line numbers in grep?

To Display Line Numbers with grep MatchesAppend the -n operator to any grep command to show the line numbers. We will search for Phoenix in the current directory, show two lines before and after the matches along with their line numbers.

How does git grep work?

`git grep` command is used to search in the checkout branch and local files. But if the user is searching the content in one branch, but the content is stored in another branch of the repository, then he/she will not get the searching output.

How do I use grep in git bash?

git grep "string to search" -> Will search the string in the complete code base. git grep -ni "string to search" -> Will list the matches without considering the case of string along with line numbers. git grep --break "search string" -> Will list the matches from different files with a line break in between.


1 Answers

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

like image 165
ThorSummoner Avatar answered Sep 22 '22 11:09

ThorSummoner