Git:git grepコマンドで特定のディレクトリのみを検索する方法

スポンサーリンク

git grepコマンドで特定のディレクトリのみを検索する方法

git grepコマンドで特定のディレクトリのみを検索するには--のあとにディレクトリを指定します。

 

オプションの説明

 --
     Signals the end of options; the rest of the parameters are <pathspec> limiters.

 <pathspec>...
     If given, limit the search to paths matching at least one pattern. Both leading paths match and glob(7) patterns are supported.

     For more details about the  syntax, see the pathspec entry in gitglossary(7).

 

--のあとにディレクトリを指定した場合

$ git grep time_t -- builtin
builtin/bugreport.c: time_t now = time(NULL);
builtin/pack-objects.c: time_t last_mtime = 0;

$ git grep time_t -- builtin perl
builtin/bugreport.c: time_t now = time(NULL);
builtin/pack-objects.c: time_t last_mtime = 0;
perl/Git.pm: my ($name, $email, $time_tz) = ident('author');
perl/Git.pm: $time_tz =~ /^\d+ [+-]\d{4}$/;

 

ディレクトリを指定しない場合

$ 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);
Git:git grepコマンドで特定のディレクトリを除外して検索する方法
git grepコマンドで特定のディレクトリを除外して検索する方法 git grepコマンドで特定のディレクトリを除外して検索するには--のあとに:^を先頭に付けてディレクトリを指定します。 オプションの説明 -- Signals the ...