在Mercurial存储库中查找文本的第一次出现

Avi*_*ram 19 mercurial grep bisect

我有一个包含大约800个变更集的Mercurial存储库,我需要找到第一个变量集,其中出现了单词Example.该单词出现在.php文件中,而不是在提交注释等.

什么是最快/最简单的方法呢?

Mar*_*tin 24

尝试 hg grep Example *.php

hg grep [OPTION]... PATTERN [FILE]...

search for a pattern in specified files and revisions

    Search revisions of files for a regular expression.

    This command behaves differently than Unix grep. It only
    accepts Python/Perl regexps. It searches repository
    history, not the working directory. It always prints the
    revision number in which a match appears.

    By default, grep only prints output for the first
    revision of a file in which it finds a match. To get it
    to print every revision that contains a change in match
    status ("-" for a match that becomes a non-match, or "+"
    for a non-match that becomes a match), use the --all
    flag.

options:

 -0 --print0              end fields with NUL
    --all                 print all revisions that match
 -f --follow              follow changeset history, or file
                          history across copies and renames
 -i --ignore-case         ignore case when matching
 -l --files-with-matches  print only filenames and revisions
                          that match
 -n --line-number         print matching line numbers
 -r --rev                 search in given revision range
 -u --user                list the author (long with -v)
 -d --date                list the date (short with -q)
 -I --include             include names matching the given
                          patterns
 -X --exclude             exclude names matching the given
                          patterns

use "hg -v help grep" to show global options
Run Code Online (Sandbox Code Playgroud)

  • 这会找到模式的*last*出现,而不是第一次出现.如何根据要求"向后"(即前进)进行此搜索?要明确的是,虽然文档说它报告"找到匹配的文件的第一次修订",但它从现在向后搜索时这样做 - 这通常是你想要的.但不是在这种情况下,如果我理解OP. (3认同)

n.c*_*lou 5

所选答案不完整: hg grep --all --files-with-matches 'PATTERN' [FILES] 通常是您想要的.