Git:git grepコマンドでマッチしたファイル名のみを表示する方法

スポンサーリンク

git grepコマンドでマッチしたファイル名のみを表示する方法

git grepコマンドでマッチしたファイル名のみを表示するには-lオプションを指定します。

 

オプションの説明

 -l, --files-with-matches, --name-only, -L, --files-without-match
     Instead of showing every matched line, show only the names of files that contain (or do not contain) matches. For better compatibility with git diff,
     --name-only is a synonym for --files-with-matches.

 

-lオプションを指定した場合

$ git grep -l time_t | head
Documentation/RelNotes/2.14.0.txt
Documentation/git-grep.txt
archive-zip.c
archive.c
blame.c
builtin/bugreport.c
builtin/pack-objects.c
commit-graph.c
commit-reach.c
commit-reach.h

 

-lオプションを指定しない場合

$ 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);