使用 diff 的输出来创建补丁

发布于 2024-07-10 21:29:20 字数 428 浏览 4 评论 0原文

我有类似的东西,

src/sim/simulate.cc
41d40
< #include "mem/mem-interface.h"
90,91d88
<             dram_print_stats_common(curTick/500);
<
src/mem/physical.hh
52d51
<   public:
55,56d53
<       public:
<
58a56,57
>       public:
>
61,62c60,61
<         virtual bool recvTiming(PacketPtr pkt); //baoyg
<
---

我相信这是使用源树中的 diff 命令创建的。 我想要的是使用该输出创建补丁,并将相同的更改应用于我的源代码树。

I have something like this

src/sim/simulate.cc
41d40
< #include "mem/mem-interface.h"
90,91d88
<             dram_print_stats_common(curTick/500);
<
src/mem/physical.hh
52d51
<   public:
55,56d53
<       public:
<
58a56,57
>       public:
>
61,62c60,61
<         virtual bool recvTiming(PacketPtr pkt); //baoyg
<
---

I believe this was created using the diff command in a source tree. What I want is to create the patch using that output, and to apply the same changes to my source tree.

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

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

发布评论

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

评论(5

野稚 2024-07-17 21:29:21

我相信 diff -u oldfile newfile > a.patch 用于创建补丁文件,尽管也可能会抛出一些其他开关(-N?)。

编辑:好的,4 年后,最后要解释一下开关的含义:

-u 创建一个 统一 差异。 统一差异是补丁程序期望作为输入获得的差异类型。 您还可以在 u 之后指定一个数字(最小 3,默认 3)以增加输出的行数。 这是为了防止 3 行不够独特,无法仅确定程序中的一个位置。

-N 将不存在的文件视为空文件,这意味着如果其中一个文件为空,它将产生大量附加内容(或参见下一点)。

此外,newfileoldfile 都可以是目录而不是单个文件。 您可能需要 -r 参数来递归任何子目录。

I believe that diff -u oldfile newfile > a.patch is used to create patch files, although some other switched may be thrown in as well (-N?).

Edit: OK, 4 years later and finally going to explain what the switches mean:

-u creates a Unified diff. Unified diffs are the kind of diffs that the patch program expects to get as input. You can also specify a number after the u (min 3, default 3) to increase the number of lines output. This is in case 3 lines isn't unique enough to pinpoint just one spot in the program.

-N treats absent files as being empty, which means it will produce a lot of additional content if one of the files is empty (or see next point).

Also, newfile and oldfile can both be directories instead of single files. You'll likely want the -r argument for this to recurse any subdirectories.

書生途 2024-07-17 21:29:21

如果你想获得与 SVN 或 git diff 相同的补丁输出,给定两个不同的文件或文件夹:

diff -Naur file1.cpp file2.cpp

If you want to get the same patch output as SVN or git diff, given two different files or folders:

diff -Naur file1.cpp file2.cpp
春风十里 2024-07-17 21:29:21

你所拥有的是非统一的差异。 patch 可以读取它,但无法进行上下文匹配,并且更有可能出错。

What you have there is a non-unified diff. patch can read it, but will be unable to make context matches and is more likely to make mistakes.

生寂 2024-07-17 21:29:21

一个(部分)补丁文件,尽管如果它们为您提供统一的差异输出会更好。

该补丁的主要问题是它没有提及正在修改哪些文件,并且由于没有提供上下文,因此文件必须准确,补丁将无法允许进行微小的更改文件。

That is a (partial) patch file, though it would have been better if they provided you with a unified diff output.

The main issue with that patch is that it doesn't mention which files are being modified, and since there is no context provided, the files must be exact, patch will be unable to allow for minor changes in the file.

够钟 2024-07-17 21:29:21

将原始帖子中的差异复制到名为 test.patch 的补丁文件中,然后运行

patch <original file> test.patch

​​@Sparr 和 @Arafangion 指出,如果您拥有用于创建原始差异的确切原始文件,则此方法效果最佳。

Copy the diff in the original post to a patch file named test.patch then run

patch <original file> test.patch

@Sparr and @Arafangion point out that this works best if you have the exact original file used to create the original diff.

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