26

If you do hg log myfile -v you see a list of changesets that the file was modified in.

In our case, in the most recent changeset, the file was removed. But you can't tell this by looking at the verbose (-v) output of hg log. Is there an easy Mercurial command you can use to determine if and when a file has been removed from the repo?


Update: Note that this is on a Windows client, and we are using Mercurial v 1.4.3

Update 2: Appears the answers below would work with a more recent version of Mercurial, however an upgrade isn't in the cards right now. Any other ideas for v 1.4.3 ???

Marcus Leon
  • 55,199
  • 118
  • 297
  • 429

3 Answers3

31

You can check which revision deleted a file (any many other interesting features) using revsets:

hg log -r 'removes(<myfile>)'

Some examples:

hg log -r 'removes(build.xml)' // where build.xml used to be in the current directory

hg log -r 'removes("**/build.xml")' // where build.xml may have been in sub directories

See hg help revsets for details.

Spina
  • 8,986
  • 7
  • 37
  • 36
Tim Henigan
  • 60,452
  • 11
  • 85
  • 78
  • doesn't seem to work for me: `abort: unknown revision 'removes(myfile)'!` – Marcus Leon Mar 24 '11 at 13:31
  • 1
    @Marcus: revsets were introduced in Mercurial v1.7. It sounds like you are using an older version. – Tim Henigan Mar 24 '11 at 13:44
  • 1
    Seems to require full repository path too (i.e. "myfile" or "./myfile" won't work if you're in a subdirectory) – Nick Mar 14 '12 at 11:57
  • 1
    +1 I've used this several times now. Note that the argument to `removes()` may require quoting. For me (on Cygwin) I get a syntax error otherwise. – harpo Nov 19 '14 at 15:55
  • thanks for the working solution! (in git it's `git log path/to/deleted_file`, i wish this port of the UI did not have to be so complicated) – Aleksandr Levchuk Apr 13 '18 at 16:34
  • I've also been getting the `abort: unknown revision 'removes()'` error. The fix is to use double quotes instead of the single quotes: `hg log -r "removes()"`. – Sunius Aug 09 '21 at 21:15
23

The --removed flag should get you what you are looking for:

hg log myfile -v --removed

From the help for hg log:

    --removed              include revisions where files were removed
Den
  • 866
  • 6
  • 6
  • Note that just `hg log myfile` will list all revisions where file was modified - including where it was removed (I believe). But I just want to find out where it was removed - not where it was modified. – Marcus Leon Mar 24 '11 at 13:32
  • The revsets solution is probably your best bet then. Might be worth updating your Mercurial version past 1.7 to get that feature. – Den Mar 24 '11 at 14:27
  • 2
    Changes where the file is removed are *not* included by default for performance reasons (in v2.1 at least). – Nick Mar 14 '12 at 12:04
3

This is what I use to list all the deleted files in my repository:

hg log --template "{rev}: {file_dels}\n" | grep -v ':\s*$'
Jeff Bauer
  • 13,890
  • 9
  • 51
  • 73
  • 1
    Regarding grep I should have noted I'm on Windows. I tried removing the part after the pipe, but it doesn't appear to be useful info (at least without the grep). – Marcus Leon Mar 24 '11 at 13:34
  • Is there an equivalent findstr command that we can run on Windows without grep? – WEFX Jan 31 '13 at 13:49
  • @WEFX The best I can figure for a `FINDSTR` equivalent is `| FINDSTR /R /V ": *$"`, but FINDSTR outputs a lot of messages like `FINDSTR: Line 29 is too long`, so you’ll ignore any big commits with it. – binki Sep 16 '13 at 18:23