2011-11-11 59 views
3

有許多提交的回購。我知道文件的名稱,並且這個東西(一個字符串,一些係數是精確的)我正在尋找,但我不知道它是什麼提交。它不再是當前的,這是肯定的,也不是以前的幾個。如何搜索回購的歷史記錄?

* 如何搜索時間明智,所以到指定的文件中說,一定事情(或整個回購協議中,我不在乎),所以它遍歷所有承諾,直到他發現它?*

對這兩個mercurial感興趣& git。目前使用這兩種方法,但我不確定這兩種方法中的任何一種是否可行。

回答

3

Mercurial有grep命令。從文檔:

汞的grep [選項] ...模式[FILE] ...

搜索中指定的文件和修訂

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. 

對於Git的模式,這個相關的問題似乎相關:

How to grep (search) committed code in the git history?

1

使用git,您可以使用鎬頭搜索。有兩個有趣的標誌來git log

-S<string> 
    Look for differences that introduce or remove an instance of <string>. 
    Note that this is different than the string simply appearing in diff 
    output; see the pickaxe entry in gitdiffcore(7) for more details. 

這可以讓你發現,添加或刪除特定字符串的提交。

-G<regex> 
    Look for differences whose added or removed line matches the given 
    <regex>. 

這可以讓您找到添加或刪除的行與正則表達式匹配的提交。

您可以通過過濾輸出git log-- filename(例如, git log -Scoeff -- myfile.c

0

水銀(鮮)有revsets,這將使找到任何東西,比用grep更容易(常用)

相關問題