2

I'd like to output ("-o") the content of a file that is version controlled in mercurial. I know this can be done using the cat command.

However, the file I am interested in has been removed, so the cat command fails with a "no such file in rev X" where X was the revision number where the file was removed.

I do not wish to restore the file. How do I output the content of such a file?

PM.
  • 644
  • 1
  • 11
  • 15

2 Answers2

1

One alternative to using cat would be to update to a revision where the file still existed. This would just be:

hg up -r$REV

as long as you're sure it still existed in $REV. Then you can just navigate to the file normally & view it, copy it somewhere, etc.

The usual considerations apply when doing any update - i.e., you generally need a clean working directory.


If you are using TortoiseHG, you could also use the "browse" feature to do something similar.

In THG Workbench, scroll down to the revision that still has the file. Then right click "Browse at Revision". This will show a treeview of the entire repository at that revision. You can just pick the file out of the tree and save it, etc.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
0

hg cat -r$REV $FILE

where $REV is the revision of the file you wish to view and $FILE is the filename.

If you are unsure of the revisions you can use hg log $FILE to show you the history, so you can choose a revision before it was deleted.

Anthony Williams
  • 66,628
  • 14
  • 133
  • 155
  • Thanks, but hg log myfile.txt returns empty. hg log -r "removes('**/myfile.txt')" only returns the changeset where it was removed. It does show a parent: Y rev but using that rev in the cat command also generates a "no such file in rev Y" – PM. Jan 23 '20 at 15:30
  • @PM did you specify the path to the file or just the filename? – StayOnTarget Jan 23 '20 at 16:42
  • @UuDdLrLrSs I tried both ( from the 'main' where I issue hg commands normally) – PM. Jan 23 '20 at 16:45