如何仅修补差异中的特定块

发布于 2024-08-16 18:28:35 字数 230 浏览 2 评论 0原文

有没有办法将差异中的单个块应用到文件?例如,假设我对文件 A 和 B 进行比较,这会产生三个差异块,每个差异块都用类似... 的内容表示

@@ -971,30 +977,28 @@

(在统一差异的情况下)。然后我希望能够将该差异输入到标准输入中,并要求补丁仅应用 Hunk N。

手动方法是剪切并粘贴有趣的 Hunk,但我并不追求这种解决方案。

Is there a way to apply a single hunk from a diff to a file? For example, say I do a diff from file A and B, and that produces three chunks of differences, each denoted with something like...

@@ -971,30 +977,28 @@

...(in the case of unified diffs). I'd then want to be able to feed that diff into stdin, and ask patch to only apply hunk N.

The manual method would be to cut-and-paste the interesting hunks, but I'm not after that kind of a solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

坠似风落 2024-08-23 18:28:35

filterdiff 可能会有所帮助。

它允许从一个/多个补丁文件中提取满足各种要求的补丁子集。例如,这里我们从文件 unified_diff.patch 中提取适用于名称与 one_file.c 匹配的文件的补丁,仅适用于原始文件的第 950 到 1050 行:

filterdiff -i *one_file.c --lines=950,1050 unified_diff.patch

提取特定/范围的帅哥:

filterdiff --hunks=1,3,5-8,15 file.patch

从邮件消息中提取补丁:

filterdiff message-with-diff-in-the-body > file.patch

等等。

filterdiff might help.

It allows extraction of subset of patches matching a variety of requirements, from one/many patch files. For example, here we extract from the file unified_diff.patch, the patches applicable to files with name matching one_file.c, only to lines 950 to 1050 of the original file:

filterdiff -i *one_file.c --lines=950,1050 unified_diff.patch

To extract specific/range of hunks:

filterdiff --hunks=1,3,5-8,15 file.patch

Extracting patches from mail messages:

filterdiff message-with-diff-in-the-body > file.patch

etc.

入画浅相思 2024-08-23 18:28:35

一些 GUI diff/patch 工具可以选择块甚至单独的行。我知道 TortoiseSVN 的 TortoiseDiff 可以这样工作。我想我见过温迪夫这样做过,但我已经有一段时间没有使用它了。

就命令行工具而言,我还没有看到任何可以满足您要求的工具。

Some of the GUI diff/patch tools have a way to select blocks or even individual lines. I know TortoiseDiff from TortoiseSVN can work this way. I think I've seen windiff do it, but it's been a while since I had to use it.

As far as command line tools, I have not seen anything that will do what you are asking.

万水千山粽是情ミ 2024-08-23 18:28:35

Emacs 不仅可以智能地编辑差异(包括一直有用的 split-hunk 操作),而且可以一次应用它们(避免需要从编辑器切换来运行 patch)。

Emacs can not only edit diffs intelligently (including the ever-useful split-hunk operation), but can apply them one hunk at a time itself (avoiding the need to switch from the editor to run patch).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文