Mercurial 可以做反向补丁吗?
场景:我“继承”了一个保留在 Mercurial 下的程序,该程序仅适用于我的系统,并对签入的某些文件进行了特定调整。我不想想要签入这些调整。
我的最新的解决方案是创建一个包含这些调整的 Mercurial 补丁文件(hg diff > patchfile);当我需要检查我的更改时,我只需反向应用补丁、提交并重新应用补丁。 (如果我完全控制源代码,我只需将所有这些小调整移动到不受版本控制的单个配置文件中,将“示例”配置文件置于版本控制下)
不幸的是,似乎虽然GNU patch
命令支持 --reverse
标志,它不支持 hg 的多文件 diff 格式作为单个补丁文件(或者也许它支持,但我只是不支持)不知道它的开关吗?)。 OTOH,hg 有自己的 patch
命令可以应用 diff,但不支持任何类型的 reverse
标志。
所以我的问题是双重的:
- 在 Mercurial 中应该如何完成?当然,坚持“调整补丁”并不是处理这种情况的唯一方法。也许 Mercurial 有一个插件或内置的东西来处理这种临时的、不可提交的更改。
- 除了应该如何完成事情之外,还有什么方法可以将这样的 Mercurial diff 补丁反向应用到像这样的 Mercurial 存储库中?在其他情况下,此类功能也很有用。
Scenario: I've "inherited" a program, kept under Mercurial, that only works on my system with specific tweaks to certain files that are checked in. I do not want to check these tweaks in.
My most recent solution to this is to create a mercurial patch file (hg diff > patchfile) containing these tweaks; when I need to check in my changes, I'll just reverse-apply the patch, commit, and re-apply the patch. (If I had full control of the source, I'd just move all these little tweaks to a single configuration file that isn't under version control, putting a "sample" config file under version control)
Unfortunately, it seems that while the GNU patch
command supports the --reverse
flag, it does not support hg's multi-file diff format as a single patch file (or maybe it does, and I just don't know the switches for it?). OTOH, hg has its own patch
command that can apply the diff, but that doesn't support any kind of reverse
flag.
So my question is twofold:
- How should this be done in mercurial? Surely hanging on to a "tweak patch" isn't the only way to handle this situation. Maybe mercurial has a plugin or something built in for such temporary, uncommittable changes.
- Aside from how things should be done, is there any way to reverse-apply such a mercurial diff-patch to a mercurial repo like this? There are other situations where such functionality would be useful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Mercurial 的
patch
命令(实际上是import
)不支持反向操作,但hg diff
支持。对其使用--reverse
,您将获得 Mercurial 可以应用的反向补丁。但是,您所描述的是一个非常常见的供应商分支样式工作流程,mercurial 可以更好地支持使用 diff 和 patch 之外的功能。
具体来说,Mercurial Queues 完全符合您的要求想。
Mercurial's
patch
command (reallyimport
) doesn't support reverse, buthg diff
does. Use--reverse
on that and you'll have a reversed patch that Mercurial can apply.However, what you're describing is a very common vendor-branch style workflow, which mercurial can better support using features other than diff and patch.
Specfically, Mercurial Queues does exactly what you want.
我发现当你有子存储库时 --reverse 方法不起作用。 IE
。如果它对任何人有帮助,这个几乎没有经过测试的脚本似乎可以完成这项工作:
I found --reverse approach did not work when you have sub repos. i.e.
. In case it helps anyone, this barely tested script seems to do the job: