Using the output of diff to create the patch

Eduardo picture Eduardo · Jan 12, 2009 · Viewed 65.9k times · Source

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.

Answer

Powerlord picture Powerlord · Jan 12, 2009

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.