手动使用 gnu 补丁时的常见做法
假设我有一个本地修改的文件 my_V1
和同一文件的较新官方版本: V2
,但它们的共同祖先 V1
已经消失了。
我想将 my_V1
的一些更改合并到 V2
中,以获得 my_V2
,什么是常见的做法是比较它们、检查补丁并应用补丁。
我所做的主要是
diff -U V2 my_V1 > my_patch #generate a unified patch
vi my_patch #review it
patch V2 -o my_V2 -i my_patch #apply
当我检查并选择要合并到 V2 的行时,似乎我必须手动指定每个块的新位置和长度,否则补丁会拒绝应用它。
这就是我们在使用gnu diff时必须承受的吗?
或者,我应该以另一种更优雅的方式使用 patch 和 diff 吗?
Say I have a locally modified file my_V1
and the newer official version of the same file: V2
, but their common ancestor V1
is gone.
And I want to merge some of changes of my_V1
into V2
in order to get a my_V2
, what is the common practice to diff them, review the patch, and applying the patch.
What I am doing is mostly like
diff -U V2 my_V1 > my_patch #generate a unified patch
vi my_patch #review it
patch V2 -o my_V2 -i my_patch #apply
And when I reviewing and picking lines to merge into V2, it seems I must manually specify the new position and length of every chunk, or patch simply refuse to apply it.
Is this what we have to bear when using gnu diff?
or, am I supposed to use patch and diff in another more more elegant way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该查看 patchutils,尤其是 filterdiff 命令。它可用于检查差异并仅保留一些更改。
You should have a look at patchutils, especially the filterdiff command. It can be used to review a diff and keep only some changes.