Find deleted files in Mercurial repository history, quickly?

大城市里の小女人 提交于 2019-12-18 10:03:46

问题


You can use hg grep, but it searches the contents of all files.

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.


回答1:


using templates is simple:

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



回答2:


Update for Mercurial 1.6

You can use revsets for this too:

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:

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"



回答3:


If you are using TortoiseHg workbench, a convenient way is to use the revision filter. Just hit ctrl+s, and then type

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.

There is also this Advanced Query Editor:




回答4:


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



回答5:


I have taken other answers and improved it.

Added "--no-merges". On large project with dev teams, there will lots of merges. --no-merger will filter out the log noise.

Change removes("**") to sort(removes("**"), -rev). For a large project with over 100K changesets, this will get to the latest files removed a lot faster. This reverses the order from starting at rev 0 to start at tip instead.

Added {author} and {desc} to ouput. 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

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



回答6:


from project root

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


来源:https://stackoverflow.com/questions/1013550/find-deleted-files-in-mercurial-repository-history-quickly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!