Help: grep

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

search for a pattern in specified files

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.


The following keywords are supported in addition to the common template keywords and functions. See also 'hg help templates'.

String. Character denoting insertion "+" or removal "-". Available if "--diff" is specified.
Integer. Line number of the match.
String. Repository-absolute path of the file.
List of text chunks.

And each entry of "{texts}" provides the following sub-keywords.

Boolean. True if the chunk matches the specified pattern.
String. Chunk content.

See 'hg help templates.operators' for the list expansion syntax.

Returns 0 if a match is found, 1 otherwise.

options ([+] can be repeated):

-0 --print0 end fields with NUL
--all an alias to --diff (DEPRECATED)
--diff search revision differences for when the pattern was added or removed
-a --text treat all files as text
-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 REV [+] search files changed within revision range
--all-files include all files in the changeset while grepping (DEPRECATED)
-u --user list the author (long with -v)
-d --date list the date (short with -q)
-T --template TEMPLATE display with template
-I --include PATTERN [+] include names matching the given patterns
-X --exclude PATTERN [+] exclude names matching the given patterns

global options ([+] can be repeated):

-R --repository REPO repository root directory or name of overlay bundle file
--cwd DIR change working directory
-y --noninteractive do not prompt, automatically pick the first choice for all prompts
-q --quiet suppress output
-v --verbose enable additional output
--color TYPE when to colorize (boolean, always, auto, never, or debug)
--config CONFIG [+] set/override config option (use '')
--debug enable debugging output
--debugger start debugger
--encoding ENCODE set the charset encoding (default: UTF-8)
--encodingmode MODE set the charset encoding mode (default: strict)
--traceback always print a traceback on exception
--time time how long the command takes
--profile print command execution profile
--version output version information and exit
-h --help display help and exit
--hidden consider hidden changesets
--pager TYPE when to paginate (boolean, always, auto, or never) (default: auto)