简体   繁体   English

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

[英]Find deleted files in Mercurial repository history, quickly?

You can use hg grep , but it searches the contents of all files.您可以使用hg grep ,但它会搜索所有文件的内容。

What if I just want to search the file names of deleted files to recover one?如果我只想搜索已删除文件的文件名来恢复文件怎么办?

I tried hg grep -I <file-name-pattern> <pattern> but this seems to return no results.我试过hg grep -I <file-name-pattern> <pattern>但这似乎没有返回任何结果。

使用模板很简单

$ hg log --template "{rev}: {file_dels}\n"

Update for Mercurial 1.6 Mercurial 1.6 更新

You can use revsets for this too:您也可以为此使用revsets

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

( Edit: Note the double * - a single one detects removals from the root of the repository only .) 编辑:注意双* - 单个检测仅从存储库的根目录删除。)


Edit : As Mathieu Longtin suggests, this can be combined with the template from dfa's answer to show you which files each listed revision removes:编辑:正如 Mathieu Longtin 所建议的那样,这可以与dfa 的答案中模板结合使用,以显示每个列出的修订版删除了哪些文件:

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

That has the virtue (for machine-readability) of listing one revision per line, but you can make the output prettier for humans by using % to format each item in the list of deletions:这具有每行列出一个修订版本的优点(对于机器可读性),但是您可以通过使用%格式化删除列表中的每个项目来使输出更适合人类:

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

If you are using TortoiseHg workbench, a convenient way is to use the revision filter.如果您使用 TortoiseHg 工作台,一个方便的方法是使用修订过滤器。 Just hit ctrl+s , and then type只需按ctrl+s ,然后键入

removes("**/FileYouWantToFind.txt")

**/ indicates that you want to search recursively in your repository. **/表示您要在存储库中递归搜索。 You can use * wildcard in the filename too.您也可以在文件名中使用*通配符。 You can combine this query with other revision sets using and , or operators.您可以使用andor运算符将此查询与其他修订集组合起来。

There is also this Advanced Query Editor:还有这个高级查询编辑器: 在此处输入图片说明

Search for a specific file you deleted efficiently, and format the result nicely:搜索您有效删除的特定文件,并很好地格式化结果:

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

Sample output:示例输出:

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

I have taken other answers and improved it.我已经接受了其他答案并对其进行了改进。

Added "--no-merges".添加了“--no-merges”。 On large project with dev teams, there will lots of merges.在有开发团队的大型项目中,会有很多合并。 --no-merger will filter out the log noise. --no-merger 将过滤掉日志噪声。

Change removes("**") to sort(removes("**"), -rev) . removes("**")更改为sort(removes("**"), -rev) For a large project with over 100K changesets, this will get to the latest files removed a lot faster.对于具有超过 100K 变更集的大型项目,这将更快地获取最新删除的文件。 This reverses the order from starting at rev 0 to start at tip instead.这颠倒了从从 rev 0 开始到从 tip 开始的顺序。

Added {author} and {desc} to ouput.向输出添加了 {author} 和 {desc}。 This will give context as to why the files was removed by displaying the log comment and who did it.这将通过显示日志注释以及是谁删除文件来提供有关为什么删除文件的上下文。

So for my use case, it was 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所以对于我的用例,它是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

Sample output:示例输出:

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

从项目根

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM