Getting old revision of renamed files

Tom Anderson tom.anderson at timgroup.com
Fri Feb 3 10:40:36 UTC 2012


On 02/02/12 17:05, Nikolaus Rath wrote:
> When I want to look at a previous revision of a file, I typically use
> 'hg revert -r rev<myfile>'.

Ouch!

> This works well as long as the file has not been renamed after rev. If
> the file has been renamed, then<myfile>  will look just as before, and
> instead I will have a "new" file somewhere else in the repository.

Unless you currently have a file with the name your file used to have, 
in which case the revert will do nothing:

hg init test
cd test
echo first >red
hg add .
hg commit -m 'added first as red'
hg mv red blue
hg commit -m 'renamed red to blue'
echo second >red
hg add .
hg commit -m 'added second as red'
hg revert -r 0 blue
cat red

> So I have to go through the "hg log -f<myfile>" output to figure out where
> the revert placed the contents. In addition to that, there seems to be
> an implicit "hg add" of the old location and name of the file, so I also
> have to call "hg remove -f" to prevent re-adding the file with the old
> name.
>
> Is there a better way to do this?
>
> I first thought that "hg cat -r rev<myfile>" would do what I want, but
> this just fails with "no such file in rev " if the file had a different
> name at that point.

Sounds like a bug in hg cat to me. Is it that hg cat takes the same 
rename-ignorant approach to history that hg log does, but that it also 
lacks the -f flag that hg log can take to make it follow renames?

tom

-- 

Tom Anderson | Developer | +44 20 7826 4312 | timgroup.com 
<http://timgroup.com/>

STATEMENT OF CONFIDENTIALITY: The information contained in this 
electronic message and any attachments to this message are intended for 
the exclusive use of the addressee(s) and may contain confidential or 
privileged information. If you are not the intended recipient, please 
notify Natalie Hall at TIM Group at either +44 20 7826 4308 or 
natalie.hall at timgroup.com and destroy all copies of this message and any 
attachments.

TIM Group is the trading name for YouDevise Limited. YouDevise Limited 
is registered in England, No. 3331176. Registered office: 3 Copthall 
Avenue, London, EC2R 7BH.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20120203/987849ae/attachment-0002.html>


More information about the Mercurial mailing list