hg grep

search revision history for a pattern in specified files

Contents

Synopsis

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

Description

Search revision history for a regular expression in the specified files or the entire project.

By default, grep prints the most recent revision number for each 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 --diff flag.

PATTERN can be any Python (roughly Perl-compatible) regular expression.

If no FILEs are specified (and -f/--follow isn't set), all files in the repository are searched, including those that don't exist in the current branch or have been deleted in a prior changeset.

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 --diff is 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

-0, --print0 end fields with NUL
--all print all revisions that match (DEPRECATED)
--diff print all revisions when the term was introduced 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[+]>
 only search files changed within revision range
--all-files include all files in the changeset while grepping (EXPERIMENTAL)
-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

[+] marked option can be specified multiple times