永久反转补丁文件
有时,无论出于何种原因,我必须生成方向错误的补丁文件(在 Linux 下)。我知道我可以通过 patch
应用它时使用 -R
开关来处理这个问题,但如果有一种方法可以永久逆转补丁,那就太好了 -文件。是否有一个实用程序可以做到这一点,或者例如可以保证工作的正则表达式?
更新
Lie Ryan建议了一种巧妙的方法来做到这一点。但是,它需要访问原始源文件。所以我想我应该更新我的问题以表明我更想要一种仅在补丁文件本身的情况下实现此目的的方法。
Sometimes, for whatever reason, I have to produce patch-files (under Linux) that are in the wrong direction. I know that I can deal with this by using the -R
switch when applying it via patch
, but it would be nice if there were a way of permanently reversing the patch-file. Is there a utility that can do this, or e.g. a regex that would be guaranteed to work?
UPDATE
Lie Ryan has suggested a neat way of doing this. However, it requires access to the original source file(s). So I suppose I should update my question to state that I'm more after a way of achieving this given only the patch-file itself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 patchutils 中的工具
interdiff(1)
。特别是,interdiff
的手册页显示:因此,
-q / --quiet
可以防止插入reverted:
行。You can use the tool
interdiff(1)
from patchutils. In particular, the man page forinterdiff
says:So,
The
-q / --quiet
prevents the insertion ofreverted:
lines.尝试:
编辑:
要反转统一差异,您需要更改三件事:
如下所示:
因此,a 的补丁头 需要反转它,所以它看起来像这样:
基本上切换顺序,并将 +++ 切换到 --- ,反之亦然。
接下来是块头:
您需要反转数字,所以它看起来像这样:
基本上,交换数字对
,最后,交换以 + 开头的每一行和以 - 开头的每一行。
编辑:
要切换块头,您可以执行以下操作:
将+切换为-,将-切换为+,您可以执行:
FINALLY:
反转补丁头,执行以下操作:
所以,最后,我们的(快速而肮脏的)脚本看起来像:
我测试了它,它似乎可以工作。
不过,为了让事情更容易维护、更干净:
Try:
EDIT:
To reverse a unified diff, you need to change three things:
So here's how a patch header for a looks like:
you need to reverse it so it looks like this:
basically switch the order, and switch +++ to --- and vice versa.
Next, the chunk header:
You need to reverse the numbers, so it look like this:
basically, switch the number pairs
and last, switch every line beginning with + and every line beginning with -.
EDIT:
to switch the chunk header, you can do:
to switch + to - and - to +, you can do:
FINALLY:
to reverse the patch header, do:
So, finally, our (quick and dirty) script looks like:
I tested it, and it seems to work.
though, to make things more maintainable, and cleaner:
我已经应用了补丁
patch -N -p0
path/file.patch
但由于代码不完整,我开始面临编译问题,我所做的就是运行此命令patch -p0 -R
patch -p0 -R
路径/file.patch
。引用了此链接I had applied a patch
patch -N -p0 < path/file.patch
but i started facing compilation issues due to incomplete code all i did was to run this commandpatch -p0 -R < path/file.patch
. Referred this link我使用以下命令反转/恢复了原始文件:
patch -Ri example.patch
附加的
-p0
或-p1
选项也可能有帮助。I reversed / restored original file with:
patch -Ri sample.patch
Additional
-p0
or-p1
options might be of help as well.