git grepコマンドでディレクトリの深さを指定して検索する方法
git grepコマンドでディレクトリの深さを指定して検索するには--max-depthオプションを指定します。
オプションの説明
--max-depth <depth> For each <pathspec> given on command line, descend at most <depth> levels of directories. A value of -1 means no limit. This option is ignored if <pathspec> contains active wildcards. In other words if "a*" matches a directory named "a*", "*" is matched literally so --max-depth is still effective.
--max-depthオプションを指定した場合(0はディレクトリを再帰的に検索しない。デフォルトは-1でディレクトリを再帰的に検索する)
$ git grep --max-depth 0 time_t | head archive-zip.c: time_t time; archive-zip.c: time = (time_t)*timestamp; archive.c: time_t archive_time; blame.c: time_t now; commit-graph.c: time_t now = time(NULL); commit-reach.c: time_t min_commit_date, commit-reach.c: time_t min_commit_date = cutoff_by_min_date ? from->item->date : 0; commit-reach.h: time_t min_commit_date, date.c:static time_t tm_to_time_t(const struct tm *tm) date.c:static time_t gm_time_t(timestamp_t time, int tz) $ git grep --max-depth 1 time_t | head 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); commit-reach.c: time_t min_commit_date, $ git grep --max-depth 2 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);
--max-depthオプションを指定しない場合
$ 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);