hg grep#
search for a pattern in specified files#
hg grep [--diff] [OPTION]... PATTERN [FILE]...
Search the working directory or revision history for a regular expression in the specified files for the entire repository.
By default, grep searches the repository files in the working directory and prints the files where it finds a match. To specify historical revisions instead of the working directory, use the --rev flag.
To search instead historical revision differences 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 --diff flag.
PATTERN can be any Python (roughly Perl-compatible) regular expression.
If no FILEs are specified and the --rev flag isn't supplied, all files in the working directory are searched. When using the --rev flag and specifying FILEs, use the --follow argument to also follow the specified FILEs across renames and copies.
Template:
The following keywords are supported in addition to the common template keywords and functions. See also `hg help templates`.
- change:
String. Character denoting insertion
+or removal-. Available if--diffis specified.- lineno:
Integer. Line number of the match.
- path:
String. Repository-absolute path of the file.
- texts:
List of text chunks.
And each entry of {texts} provides the following sub-keywords.
- matched:
Boolean. True if the chunk matches the specified pattern.
- text:
String. Chunk content.
See `hg help templates.operators` for the list expansion syntax.
Returns 0 if a match is found, 1 otherwise.
Options
Every command accepts the global options.
|
|
end fields with NUL |
|
search revision differences for when the pattern was added or removed |
|
|
|
treat all files as text |
|
|
follow changeset history, or file history across copies and renames |
|
|
ignore case when matching |
|
|
print only filenames and revisions that match |
|
|
print matching line numbers |
|
|
search files changed within revision range |
|
|
list the author (long with -v) |
|
|
list the date (short with -q) |
|
|
display with template |
|
|
include names matching the given patterns |
|
|
exclude names matching the given patterns |
Options marked [+] can be repeated.