git grepコマンドでファイル名をマッチした行の先頭にまとめて表示する方法
git grepコマンドでファイル名をマッチした行の先頭にまとめて表示するには--headingオプションを指定します。
オプションの説明
--heading Show the filename above the matches in that file instead of at the start of each shown line.
--headingオプションを指定した場合(-nオプションは行番号を表示)
$ git grep --heading -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]'`:: 309: Looks for `time_t` in all tracked .c and .h files in the working archive-zip.c 599: time_t time; 605: time = (time_t)*timestamp; archive.c 438: time_t archive_time;
--headingオプションを指定しない場合
$ 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);