git grepコマンドでマッチした行番号を表示する方法
git grepコマンドでマッチした行番号を表示するには-nオプションを指定します。
オプションの説明
-n, --line-number Prefix the line number to matching lines.
-nオプションを指定した場合
$ git grep -n time_t | head Documentation/RelNotes/2.14.0.txt:141: * Some platforms have ulong that is smaller than time_t, and our Documentation/git-grep.txt:308:`git grep 'time_t' -- '*.[ch]'`:: Documentation/git-grep.txt:309: Looks for `time_t` in all tracked .c and .h files in the working archive-zip.c:599: time_t time; archive-zip.c:605: time = (time_t)*timestamp; archive.c:438: time_t archive_time; blame.c:187: time_t now; builtin/bugreport.c:127: time_t now = time(NULL); builtin/pack-objects.c:1164: time_t last_mtime = 0; commit-graph.c:2187: time_t now = time(NULL);
-nオプションを指定しない場合
$ git grep time_t | head Documentation/RelNotes/2.14.0.txt: * Some platforms have ulong that is smaller than time_t, and our Documentation/git-grep.txt:`git grep 'time_t' -- '*.[ch]'`:: Documentation/git-grep.txt: Looks for `time_t` in all tracked .c and .h files in the working archive-zip.c: time_t time; archive-zip.c: time = (time_t)*timestamp; archive.c: time_t archive_time; blame.c: time_t now; builtin/bugreport.c: time_t now = time(NULL); builtin/pack-objects.c: time_t last_mtime = 0; commit-graph.c: time_t now = time(NULL);