Retrieve old version of a file without changing working copy parent

前端 未结 2 539
温柔的废话
温柔的废话 2021-02-05 01:28

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

相关标签:
2条回答
  • 2021-02-05 02:19

    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
    
    0 讨论(0)
  • 2021-02-05 02:30

    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.

    0 讨论(0)
提交回复
热议问题