代码之家  ›  专栏  ›  技术社区  ›  wsorenson

在Mercurial存储库历史记录中快速查找已删除的文件?

  •  57
  • wsorenson  · 技术社区  · 15 年前

    您可以使用hg grep,但它会搜索所有文件的内容。

    如果我只想搜索已删除文件的文件名来恢复一个文件呢?

    我试过hg grep-i 文件名模式 模式 但这似乎没有结果。

    6 回复  |  直到 7 年前
        1
  •  84
  •   dfa    15 年前

    使用 templates is simple :

    $ hg log --template "{rev}: {file_dels}\n"
    
        2
  •  49
  •   Community CDub    7 年前

    Mercurial 1.6的更新

    你可以使用 revsets 为此:

    hg log -r "removes('**')"
    

    ( 编辑: 注意双重 * - a single one detects removals from the root of the repository only )


    编辑 :正如Mathieu Longtin所建议的,这可以与 template dfa's answer 展示给你看 哪一个 每个列出的修订版删除的文件:

    hg log -r "removes('**')" --template "{rev}: {file_dels}\n"
    

    它的优点(对于机器可读性)是每行列出一个修订版,但是您可以使用 % 要格式化删除列表中的每个项目:

    hg log -r "removes('**')" --template "{rev}:\n{file_dels % '{file}\n'}\n"
    
        3
  •  6
  •   quamrana Ryuzaki L    8 年前

    如果您使用的是TortoiseHg工作台,那么一种方便的方法是使用修订过滤器。刚刚击中 ctrl+s 然后键入类型

    removes("**/FileYouWantToFind.txt")
    

    **/ 指示要在存储库中递归搜索。 你可以使用 * 文件名中也包含通配符。您可以使用 and , or 运算符。

    还有这个高级查询编辑器: enter image description here

        4
  •  0
  •   mpen    8 年前

    有效地搜索您删除的特定文件,并将结果格式化:

    hg log --template "File(s) deleted in rev {rev}: {file_dels % '\n  {file}'}\n\n" -r 'removes("**/FileYouWantToFind.txt")'
    

    样品输出:

    File(s) deleted in rev 33336: 
      class/WebEngineX/Database/RawSql.php
    
    File(s) deleted in rev 34468: 
      class/PdoPlus/AccessDeniedException.php
      class/PdoPlus/BulkInsert.php
      class/PdoPlus/BulkInsertInfo.php
      class/PdoPlus/CannotAddForeignKeyException.php
      class/PdoPlus/DuplicateEntryException.php
      class/PdoPlus/Escaper.php
      class/PdoPlus/MsPdo.php
      class/PdoPlus/MyPdo.php
      class/PdoPlus/MyPdoException.php
      class/PdoPlus/NoSuchTableException.php
      class/PdoPlus/PdoPlus.php
      class/PdoPlus/PdoPlusException.php
      class/PdoPlus/PdoPlusStatement.php
      class/PdoPlus/RawSql.php
    
        5
  •  0
  •   Techwolf Lupindo    7 年前

    我已经得到了其他答案并改进了它。

    添加了“——没有合并”。在有开发团队的大型项目中,会有很多合并。--任何合并都不能滤除原木噪音。

    变化 removes("**") sort(removes("**"), -rev) . 对于一个拥有超过10万个变更集的大型项目,这将更快地得到最新删除的文件。这将颠倒从0版开始到提示开始的顺序。

    将作者和描述添加到输出。这将通过显示日志注释以及是谁删除了文件来提供上下文。

    所以对于我的用例来说, hg log --template "File(s) deleted in rev {rev}: {author} \n {desc}\n {file_dels % '\n {file}'}\n\n" -r 'sort(removes("**"), -rev)' --no-merges

    样品输出:

    File(s) deleted in rev 52363: Ansariel 
     STORM-2141: Fix various inventory floater related issues:
    * Opening new inventory via Control-Shift-I shortcut uses legacy and potentinally dangerous code path
    * Closing new inventory windows don't release memory
    * During shutdown legacy and inoperable code for inventory window cleanup is called
    * Remove old and unused inventory legacy code
    
      indra/newview/llfloaterinventory.cpp
      indra/newview/llfloaterinventory.h
    
    File(s) deleted in rev 51951: Ansariel 
     Remove readme.md file - again...
    
      README.md
    
    File(s) deleted in rev 51856: Brad Payne (Vir Linden) <vir@lindenlab.com> 
     SL-276 WIP - removed avatar_skeleton_spine_joints.xml
    
      indra/newview/character/avatar_skeleton_spine_joints.xml
    
    File(s) deleted in rev 51821: Brad Payne (Vir Linden) <vir@lindenlab.com> 
     SL-276 WIP - removed avatar_XXX_orig.xml files.
    
      indra/newview/character/avatar_lad_orig.xml
      indra/newview/character/avatar_skeleton_orig.xml
    
        6
  •  -1
  •   Matt holmes    9 年前

    从项目根目录

    hg status . | grep "\!" >> /tmp/filesmissinginrepo.txt