2012-03-08 8 views

Respuesta

20

tratar 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 
+3

Hoy aprendí algo increíble :) –

+1

'Busca en el historial del repositorio, no en el directorio de trabajo' Tenga en cuenta que esto solo es cierto si no especifica una extensión de archivo. El ejemplo proporcionado solo se verá en los archivos '.php' en el directorio de trabajo actual. – MrLore

+2

Esto encuentra la * última * aparición del patrón, no la primera. ¿Cómo hace esta búsqueda "hacia atrás" (es decir, hacia adelante), como se solicitó? Para que quede claro, aunque el documento dice que informa "la primera revisión de un archivo en el que encuentra una coincidencia", lo hace al buscar hacia atrás desde el presente, que generalmente es lo que quiere. Pero no en este caso, si entiendo el OP. – harpo

0
hg help filesets 
... 
"grep(regex)" 
     File contains the given regular expression. 

hg locate "set:grep(Example) and **.php"

o

hg locate "set:**.php and (**Example*)"

+0

'hg help locate' me dice que' Por defecto, este comando busca en todos los directorios en el directorio de trabajo', por lo que no se buscarán conjuntos de cambios. – Martin

+0

@Martin - conjunto de archivos de conjunto de archivos, para lo cual hacemos el registro. hg log 'hg locate ...' –

2

La respuesta seleccionada es incompleta: hg grep --all --files-with-matches 'PATTERN' [FILES] es normalmente lo que quieres.

Cuestiones relacionadas