Question

We have a situation where we know a keyword used in one particular mercurial commit in a repository. But we don't know what commit that is in. Obviously I can go through each committed file and eventually find the keyword and how it was used, but that would be a lot of tedious work.

Is there a way in mercurial to search for a string across ALL committed code in the repository?

Was it helpful?

Solution

hg grep does exactly that.

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.

Returns 0 if a match is found, 1 otherwise.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top