2012-03-08 31 views

Odpowiedz

20

spróbować 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

dzisiaj nauczyłem się czegoś niesamowitego :) –

+1

'Przeszukuje historię repozytorium, a nie katalog roboczy' Zauważ, że jest to prawdziwe, jeśli nie podasz rozszerzenia pliku. Podany przykład będzie wyglądał tylko w plikach '.php' w bieżącym katalogu roboczym. – MrLore

+2

Znajduje * ostatnie * wystąpienie wzorca, a nie pierwsze. W jaki sposób, zgodnie z wnioskiem, wyszukiwanie to odbywa się "wstecz" (tj. W przód)? Żeby było jasne, chociaż doktor mówi, że zgłasza "pierwszą rewizję pliku, w którym znajduje dopasowanie", robi to podczas wyszukiwania wstecz od chwili obecnej - która zwykle jest tym, czego potrzebujesz. Ale nie w tym przypadku, jeśli rozumiem PO. – harpo

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

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

lub

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

+0

'hg help locate' mówi mi, że' Domyślnie ta komenda przeszukuje wszystkie katalogi w katalogu roboczym. \ Więc nie będą wyszukiwane żadne zestawy zmian. – Martin

+0

@Martin - zestaw plików daje zestaw plików, dla którego robimy log. hg log 'hg locate ...' –

2

Wybrana odpowiedź jest niekompletna: hg grep --all --files-with-matches 'PATTERN' [FILES] jest zwykle tym, czego potrzebujesz.

Powiązane problemy