Reputation: 21058
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.
Upvotes: 46
Views: 73200
Reputation: 1304
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
Upvotes: 19
Reputation: 1185
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.
Upvotes: 1
Reputation: 88846
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.
Upvotes: 81
Reputation: 11950
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.
Upvotes: 2
Reputation: 7732
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.
Upvotes: 3