我有一个包含约 800 个变更集的 Mercurial 存储库,我需要找到出现单词Example的第一个变更集。该词出现在 .php 文件中,而不是提交评论等。
最快/最简单的方法是什么?
尝试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
所选答案不完整:
hg grep --all --files-with-matches 'PATTERN' [FILES]
通常是你想要的。
hg help filesets
...
"grep(regex)"
File contains the given regular expression.
hg locate "set:grep(Example) and **.php"
或者
hg locate "set:**.php and (**Example*)"
您可能想要使用 hg grep 的--diff
( --all
is deprecated) 标志。它搜索差异而不是文件内容本身,这将导致您将获得出现或删除单词Example的所有变更集/修订。
现在要获得第一个命中,您需要通过-r
标志以 revlog 顺序传递它。也就是从 0 到小费搜索修订。(-r 0:提示)
对于 .php 文件,您需要传递-I
用于文件名模式的标志。
所以你的命令将是:
hg grep --all -r 0:tip "Example" -I "*.php"