21

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

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

4

4 回答 4

25

尝试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
于 2012-03-08T14:13:30.630 回答
9

所选答案不完整:

hg grep --all --files-with-matches 'PATTERN' [FILES]

通常是你想要的。

于 2016-06-30T16:38:37.447 回答
0
hg help filesets
...
"grep(regex)"
      File contains the given regular expression.

hg locate "set:grep(Example) and **.php"

或者

hg locate "set:**.php and (**Example*)"

于 2012-03-08T14:34:35.950 回答
0

您可能想要使用 hg grep 的--diff( --allis deprecated) 标志。它搜索差异而不是文件内容本身,这将导致您将获得出现或删除单词Example的所有变更集/修订。

现在要获得第一个命中,您需要通过-r标志以 revlog 顺序传递它。也就是从 0 到小费搜索修订。(-r 0:提示

对于 .php 文件,您需要传递-I用于文件名模式的标志。

所以你的命令将是:

hg grep --all -r 0:tip "Example" -I "*.php"
于 2018-08-15T19:30:19.870 回答