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).

 EXAMPLES
     git grep solution -- :^Documentation
         Looks for solution, excluding files in Documentation.

 

--のあとに:^を先頭に付けてディレクトリを指定した場合

$ git grep time_t -- :^Documentation | 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;
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,
commit-reach.c: time_t min_commit_date = cutoff_by_min_date ? from->item->date : 0;
commit-reach.h: time_t min_commit_date,

$ git grep time_t -- :^Documentation :^builtin | 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,
compat/mingw.c:static inline long long filetime_to_hnsec(const FILETIME *ft)
compat/mingw.c:static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)

 

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

$ 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 end of option...