Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding first appearance of text in Mercurial repository

I have a Mercurial repository with ~800 changesets and I need to find the first changeset where the word Example appeared. The word appears inside a .php file and not on a commit comment etc.

What is the quickest/easiest way to do that?

like image 731
Aviram Avatar asked Mar 08 '12 13:03

Aviram


People also ask

What does hg commit do?

Use the command hg update to switch to an existing branch. Use hg commit --close-branch to mark this branch head as closed. When all heads of a branch are closed, the branch will be considered closed.

How do I know my Mercurial version?

If you already have Mercurial installed, make sure you have version 1.7 or later. To check, enter hg --version at the command line.

What does hg update do?

Description. Update the repository's working directory to the specified changeset. If no changeset is specified, update to the tip of the current named branch and move the active bookmark (see hg help bookmarks). Update sets the working directory's parent revision to the specified changeset (see hg help parents).

How do I create a Mercurial repository?

Create a local Mercurial repository Open the project you want to store in a repository. From the main menu, choose Hg | Create Mercurial Repository. Specify the location of the new repository.


2 Answers

try 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 
like image 50
Martin Avatar answered Sep 23 '22 15:09

Martin


The selected answer is incomplete:

hg grep --all --files-with-matches 'PATTERN' [FILES] 

is normally what you want.

like image 35
n.caillou Avatar answered Sep 24 '22 15:09

n.caillou