在 Mercurial 中,如何将反向补丁应用于特定文件?
与Mercurial:在一个存储库中的分支之间合并一个文件 ,我正在尝试对单个文件执行取消操作,即使该文件是被取消的修订版本的众多参与者之一。
HG 是面向变更集的工具,它不想对文件进行操作。
我能找到的最接近的是使用 hg export 创建差异,手动编辑差异,然后 hg import 以相反的顺序修补文件。
..但后来我遇到了这个恼人的情况 http:// hgbook.red-bean.com/read/finding-and-fixing-mistakes.html 声称有一个 hg patch
的 --reverse 选项,但实际上没有。
因此,我能想到的最接近的方法是生成如上所述的手动编辑补丁,然后使用 vanilla patch -R 应用反向补丁。
hg backout 命令在这里似乎很有用,但实际上是转移注意力。
一定有更好的方法,不是吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以仅使用
-I
(包括与给定模式匹配的名称)参数通过一行进行回退:示例脚本:
示例输出:
结果文件内容:
请注意,在取消中间变更集之后,file1 在第一行中缺少空格,并且详细日志仅显示取消中更改的一个文件:
You can do it using just the
-I
(include names matching the given patterns) argument for backout with a single line:Example Script:
Sample output:
Resulting File Contents:
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:
这就是我要做的:使用尖端修订版的新克隆。
将反转的更改合并到工作副本中。
现在将有问题的文件复制到常规工作副本并提交
并丢弃上面创建的克隆。
这样,mercurial 就不知道
revision_where_the_change_happened
与此提交之间存在联系。 如果您希望 Mercurial 记住这一点,请在将回退提交合并到工作副本之后并在提交之前执行此操作。 对于第二种方式,您不需要处理克隆,因为您想保留回退提交。
我猜想您使用哪种方式的选择取决于特定文件更改占更改集的大小。
Here's what I would do: Use a fresh clone of the tip revision.
to merge the reversed changes into the working copy.
Now copy the file in question to your regular working copy and commit
and throw away the clone you created above.
This way, mercurial doesn't know that there is a connection between
revision_where_the_change_happened
and this commit. If you want mercurial to remember this, instead do aafter merging the backout commit into the working copy and before commiting. For the second way, you don't need to work on a clone, because you want to keep the backout commit.
I would guess that the choice of which way you use depends on how big a part of the changeset the particular file change was.
使用恢复命令。
这应该将文件内容恢复到修订版 1 中的版本。
然后您可以进一步编辑它并正常提交。
Use the revert command.
This should revert the contents of file to the version in revision 1.
You can then further edit it and commit as normal.