突击Mercurial SCM(HG)13---回退到指定版本

团队开发中,版本回退是老生常谈了。通常版本回退的原因是代码中出现重大错误了,要回退到上一个可运行的版本。
这是一个很危险的动作,而我们使用revert命令来做这个危险动作。

$ hg revert --help
hg revert [OPTION]... [-r REV] [NAME]...

restore files to their checkout state

    Note:
       To check out earlier revisions, you should use "hg update REV". To
       cancel an uncommitted merge (and lose your changes), use "hg update
       --clean .".

    Returns 0 on success.

options ([+] can be repeated):

 -a --all                 revert all changes when no arguments given
 -d --date DATE           tipmost revision matching date
 -r --rev REV             revert to the specified revision
 -C --no-backup           do not save backup copies of files
 -I --include PATTERN [+] include names matching the given patterns
 -X --exclude PATTERN [+] exclude names matching the given patterns
 -n --dry-run             do not perform actions, just print output

(some details hidden, use --verbose to show complete help)

帮助中提到如果check out早期的版本,用hg update REV较好。

这次我们用revert回退到前一个版本,首先看看hg log:

$ hg log
changeset:   16:6b7d0fecb27b
tag:         tip
user:        zhaoyun
date:        Fri Jan 29 14:25:09 2016 +0800
summary:     fix some critical bug

changeset:   15:59958f71202a
user:        zhugeliang
date:        Wed Jan 27 11:42:40 2016 +0800
summary:     add xxx feature

执行revert命令

$ hg revert -r 59958f71202a --all
reverting xxx/xxx/xxx.java

版本回退了,再次进行commit+push就可以了。

你可能感兴趣的:(SCM,突击Mercurial,SCM(HG))