如何在Mercurial中查看以前版本的文件

时间:2010-12-24 02:53:57

标签: mercurial

我使用mercurial对目录中的一些文件进行版本控制。假设我有10个提交(10个更改集或修订版)。我想查看一个特定的文件,比如thisFile.py,看看它的第7版。我不想恢复到这个旧版本。我不想在以前的版本中进行任何更改或修复任何错误。我只是想看到它,而不会以任何方式影响文件的最新版本或mercurial历史。有一个简单的方法吗?

3 个答案:

答案 0 :(得分:63)

hg cat命令与-r(修订版)参数一起使用。

hg cat path_to/myfile.cpp -r 46

其中46是修订号(使用hg log查看修订历史记录)

答案 1 :(得分:10)

hg cat [OPTION]... FILE...

Print the specified files as they were at the given revision. 
If no revision is given, the parent of the working directory is used, 
or tip if no revision is checked out.

Output may be to a file, in which case the name of the file is given 
using a format string. The formatting rules are the same as for the 
export command, with the following additions:
%s: basename of file being printed
%d: dirname of file being printed, or '.' if in repository root
%p: root-relative path name of file being printed

Returns 0 on success.

options:
-o, --output    print output to file with formatted name
-r, --rev   print the given revision
--decode    apply any matching decode filter
-I, --include   include names matching the given patterns
-X, --exclude   exclude names matching the given patterns

答案 2 :(得分:6)

要提取特定文件的特定版本,您可以在Windows中执行此操作:

hg cat "<FileToBeExtractedPath>" -r 9 > "<ExtractionPath>"

这里,9是修订号。

甚至更好:

hg cat "<FileToBeExtractedPath>" -r 9 -o "<ExtractionPath>"