Retrieve old version of a file without changing working copy parent

老子叫甜甜 提交于 2019-12-04 08:49:29

问题


How do you get a copy of an earlier revision of a file in Mercurial without making that the new default working copy of the file in your workspace?

I've found the hg revert command and I think it does what I want but I'm not sure.

I need to get a copy of an earlier revision of my code to work with for a few minutes. But I don't want to disturb the current version which is working fine.

So I was going to do this:

hg revert -r 10 myfile.pls

Is there a way to output it to a different directory so my current working version of the file is not disturbed? Something like:

hg revert -r 10 myfile.pls > c:\temp\dump\myfile_revision10.pls

回答1:


The cat command can be used to retrieve any revision of a file:

$ hg cat -r 10 myfile.pls

You can redirect the output to another file with

$ hg cat -r 10 myfile.pls > old.pls

or by using the --output flag. If you need to do this for several files, then take a look at the archive command, which can do this for an entire project, e.g.,

$ hg archive -r 10 ../revision-10

This creates the folder revision-10 which contains a snapshot of your repository as it looked in revision 10.

However, most of the time you should just use the update command to checkout an earlier revision. Update is the command you use to bring the working copy up to date after pulling in new changes, but the command can also be used to make your working copy outdated if needed. So

$ hg update -r 10   # go back
(look at your files, test, etc...)
$ hg update         # go back to the tip



回答2:


The command you use is this:

hg cat -r 10 myfile.pls > C:\temp\dump\myfile_revision10.pls

Knowing a bit of Unix helps with Mercurial commands. Perhaps cat should have a built in alias print or something similar.



来源:https://stackoverflow.com/questions/3597206/retrieve-old-version-of-a-file-without-changing-working-copy-parent

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