您可以仅使用-I
(包括与给定模式匹配的名称) 参数来执行此操作,以使用单行进行回退:
hg backout --merge -I thefiletorevert -m 'message' OFFENDINGREVISIONID
示例脚本:
hg init testrepo
cd testrepo
echo -e "line1\n\nline3" > file1
echo -e "line1\n\nline3" > file2
hg commit -A -m 'changes to two files'
perl -pi -e 's/line1/line 1/' file1
perl -pi -e 's/line1/line 1/' file2
hg commit -m 'put spaces in line1'
perl -pi -e 's/line3/line 3/' file1
perl -pi -e 's/line3/line 3/' file2
hg commit -m 'put spaces in line3'
hg backout --merge -I file1 -m 'remove spaces from line1' 1
样本输出:
adding file1
adding file2
reverting file1
created new head
changeset 3:6d354f1ad4c5 backs out changeset 1:906bbeaca6a3
merging with changeset 3:6d354f1ad4c5
merging file1
0 files updated, 1 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
结果文件内容:
file1:line1
file1:line 3
file2:line 1
file2:line 3
请注意,在中间变更集回退后,file1 在第一行中缺少空间,并且详细日志显示回退中仅更改了一个文件:
$ hg log -v -r tip
changeset: 3:6d354f1ad4c5
tag: tip
parent: 1:906bbeaca6a3
user: Ry4an Brase <ry4an@mini>
date: Mon Sep 14 12:17:23 2009 -0500
files: file1
description:
remove spaces from line1