以Mercurial为例,如何对特定文件应用反向修补程序? [英] In mercurial, how do I apply a reverse-patch to a particular file?
问题描述
与> Mercurial:在一个分支之间合并一个文件repo ,即使该文件是要撤消修订的许多参与者之一,我仍在尝试对单个文件执行撤消操作.
HG是它的面向变更集的工具,它不希望对文件进行操作.我能找到的最接近的方法是使用hg导出创建差异,手动编辑差异,然后进行hg导入以相反的顺序修补文件.
..但是后来我遇到了一个令人讨厌的情况,其中 http ://hgbook.red-bean.com/read/finding-and-fixing-mistakes.html 声称,如果没有hg patch
,则有一个--reverse选项.
所以我能想到的最接近的方法是生成一个如上所述的手工编辑补丁,然后使用香草补丁-R来应用反向补丁.
hg backout
命令在这里似乎很有用,但实际上是一个红色的鲱鱼.
有更好的方法,不是吗?
您可以仅使用-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
Related to Mercurial: Merging one file between branches in one repo , I'm trying to perform a backout operation on a single file, even though that file was one of many participants in the revision being backed out.
HG being the changeset-oriented tool that it is, it doesn't want to operate on files.
Closest I could find was to use hg export to create a diff, hand-edit the diff, and then hg import to patch the file in reverse order.
..but then I hit this annoying situation where http://hgbook.red-bean.com/read/finding-and-fixing-mistakes.html claims that there is a --reverse option to hg patch
when there is not.
So the closest thing I can think of is to generate a hand-edited patch as above, and then using vanilla patch -R to apply a reverse patch.
The hg backout
command would seem to be useful here, but is actually a red herring.
There has GOT to be a better way, no?
You can do it using just the -I
(include names matching the given patterns) argument for backout with a single line:
hg backout --merge -I thefiletorevert -m 'message' OFFENDINGREVISIONID
Example Script:
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
Sample output:
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)
Resulting File Contents:
file1:line1
file1:line 3
file2:line 1
file2:line 3
notice that file1 is missing it's space in line one after the backout of the middle changeset, and the verbose log shows only one file changed in the backout:
$ 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
这篇关于以Mercurial为例,如何对特定文件应用反向修补程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!