Git:git grepコマンドで単語単位で検索する方法

スポンサーリンク

git grepコマンドで単語単位で検索する方法

git grepコマンドで単語単位で検索するには-wオプションを指定します。

 

オプションの説明

 -w, --word-regexp
     Match the pattern only at word boundary (either begin at the beginning of a line, or preceded by a non-word character; end at the end of a line or
     followed by a non-word character).

 

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

$ git grep -w NONE | head
builtin/reset.c:enum reset_type { MIXED, SOFT, HARD, MERGE, KEEP, NONE };
builtin/reset.c:        int reset_type = NONE, update_ref_status = 0, quiet = 0;
builtin/reset.c:                if (reset_type != NONE)
builtin/reset.c:                else if (reset_type != NONE)
builtin/reset.c:        if (reset_type == NONE)
connect.c:                              printf("Diag: port=%s\n", port ? port : "NONE");
t/t5500-fetch-pack.sh:          ehost=$(echo $3$4 | sed -e "s/22$/:22/" -e "s/NONE//")
t/t5500-fetch-pack.sh:                                  check_prot_host_port_path $p://$h/$r $p "$h" NONE "/$r"
t/t5500-fetch-pack.sh:                                  check_prot_host_port_path $p://$h/~$r $p "$h" NONE "~$r"
t/t5500-fetch-pack.sh:                  check_prot_host_port_path $h:$r $p "$h" NONE "$r"

 

-wオプションを指定しない場合(OBJ_NONEやPARSE_OPT_NONEGなどもマッチ)

$ git grep NONE | head
alloc.c:        obj->type = OBJ_NONE;
apply.c:                        PARSE_OPT_NONEG, apply_option_parse_exclude),
apply.c:                        PARSE_OPT_NONEG, apply_option_parse_include),
bisect.c:               add_name_decoration(DECORATION_NONE, buf.buf, obj);
builtin/am.c:   o.detect_directory_renames = MERGE_DIRECTORY_RENAMES_NONE;
builtin/am.c:                   1, PARSE_OPT_NONEG),
builtin/am.c:                   0, PARSE_OPT_NONEG),
builtin/am.c:                          PARSE_OPT_NONEG, am_option_parse_quoted_cr),
builtin/am.c:             PARSE_OPT_CMDMODE | PARSE_OPT_OPTARG | PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
builtin/blame.c:        return OBJ_NONE < oid_object_info(the_repository, &oid, NULL);