使用 diff 的输出来创建补丁
我有类似的东西,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我相信
diff -u oldfile newfile > a.patch
用于创建补丁文件,尽管也可能会抛出一些其他开关(-N?)。编辑:好的,4 年后,最后要解释一下开关的含义:
-u
创建一个 统一 差异。 统一差异是补丁程序期望作为输入获得的差异类型。 您还可以在u
之后指定一个数字(最小 3,默认 3)以增加输出的行数。 这是为了防止 3 行不够独特,无法仅确定程序中的一个位置。-N
将不存在的文件视为空文件,这意味着如果其中一个文件为空,它将产生大量附加内容(或参见下一点)。此外,
newfile
和oldfile
都可以是目录而不是单个文件。 您可能需要 -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 theu
(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
andoldfile
can both be directories instead of single files. You'll likely want the-r
argument for this to recurse any subdirectories.如果你想获得与 SVN 或 git diff 相同的补丁输出,给定两个不同的文件或文件夹:
If you want to get the same patch output as SVN or git diff, given two different files or folders:
你所拥有的是非统一的差异。 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.
那是一个(部分)补丁文件,尽管如果它们为您提供统一的差异输出会更好。
该补丁的主要问题是它没有提及正在修改哪些文件,并且由于没有提供上下文,因此文件必须准确,补丁将无法允许进行微小的更改文件。
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.
将原始帖子中的差异复制到名为
test.patch
的补丁文件中,然后运行@Sparr 和 @Arafangion 指出,如果您拥有用于创建原始差异的确切原始文件,则此方法效果最佳。
Copy the diff in the original post to a patch file named
test.patch
then run@Sparr and @Arafangion point out that this works best if you have the exact original file used to create the original diff.