我有一个包含大约800个变更集的Mercurial存储库,我需要找到第一个变量集,其中出现了示例这个词。该单词出现在.php文件中,而不是在提交注释等中。
最快/最简单的方法是什么?
答案 0 :(得分:23)
尝试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
答案 1 :(得分:5)
所选答案不完整:
hg grep --all --files-with-matches 'PATTERN' [FILES]
通常是你想要的。
答案 2 :(得分: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*)"
答案 3 :(得分:0)
您可能要使用hg grep的--diff
(不推荐使用--all
)标志。它搜索差异而不是文件内容本身,这将导致,您将获得所有更改集/修订,其中出现或删除了示例一词。
现在要获得第一个匹配,您需要通过-r
标志以revlog顺序传递此匹配。也就是说,修订版将从0到小费搜索。 ( -r 0:tip )
对于.php文件,您需要传递-I
标志,用于文件名模式。
所以您的命令将是:
hg grep --all -r 0:tip "Example" -I "*.php"