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

Cur*_*arn 46 mercurial

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

Joe*_*sky 66

hg cat命令与-r(revision)参数一起使用.

hg cat path_to/myfile.cpp -r 46
Run Code Online (Sandbox Code Playgroud)

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


Thi*_*ilo 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
Run Code Online (Sandbox Code Playgroud)


use*_*353 6

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

hg cat "<FileToBeExtractedPath>" -r 9 > "<ExtractionPath>"
Run Code Online (Sandbox Code Playgroud)

这里,9是修订号.

甚至更好:

hg cat "<FileToBeExtractedPath>" -r 9 -o "<ExtractionPath>"
Run Code Online (Sandbox Code Playgroud)