2012-03-08 66 views
16

我有〜800名的變更一Mercurial庫,我需要找到第一變更這裏所說的出現。這個詞出現一個PHP文件裏,而不是在提交註釋等查找文本的第一次出現在Mercurial庫

什麼是做到這一點的最快/最簡單的方法是什麼?

回答

20

嘗試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

我學到了一些東西真棒:) – 2012-03-08 18:10:03

+1

'它搜索庫的歷史,而不是工作directory'請注意,這是唯一真正的,如果你不指定文件擴展名。所提供的例子只會查看當前工作目錄中的'.php'文件。 – MrLore 2015-08-14 10:34:02

+2

這會找出* pattern的* last *發生,而不是第一個。按照要求,你如何「向後」(即向前)進行搜索?清楚的是,雖然文檔說它報告「找到匹配的文件的第一個修訂版本」,但它從現在向後搜索時會這樣做 - 這通常是您想要的。但在這種情況下,如果我理解OP,則不是。 – harpo 2015-09-25 14:13:09

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

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

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

+0

'hg help locate'告訴我,'默認情況下,這個命令搜索工作目錄中的所有目錄。'因此不會搜索任何變更集。 – Martin 2012-03-08 15:52:37

+0

@Martin - 文件集給我們做日誌的文件集。 hg log'hg locate ...' – 2012-03-08 16:51:44

2

選擇的答案是不完整的: hg grep --all --files-with-matches 'PATTERN' [FILES] 通常是你想要的。今天

相關問題