Re: Reading and applying patches

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05Sep2006 01:44, Todd Zullinger <tmz@xxxxxxxxx> wrote:
| Chong Yu Meng wrote:
| > --- mlrate/mlrate.c 2003-01-27 10:31:31.000000000 +0100 
| > +++ mlrate.new/mlrate.c 2004-11-22 12:37:52.086783325 +0100 
| > @@ -25,6 +25,8 @@ 
| > #include <string.h> 
| > ... and continues for a bit longer
| > 
| > I assume that I should copy and paste the text into a separate file
| > and save it. But how do I apply the patch to the source file, which
| > is mlrate.c? 
| 
| You assume correctly.

It's worth mentioning that patch is pretty forgiving. You can usually
save the entire message to a file; patch is happy to skip past the leading
text up to the actual patch data (the output of a diff command, btw).

[...]
| > Also, how do I read the file? From some patch files I have come
| > across, they have "pluses" and "minuses" and other notation. What do
| > they mean?
| 
| Lines beginning with a plus are being added by the patch, lines with a
| minus are being removed.  The lines that start with either 3 minuses
| or plusses indicate the path of file that's being patched.

Also "!" prefixes lines in both parts that replace each other; the "+"
and "-" prefixes  are where lines are removes or added respectively
without any new (or old, respectively) text.

Patch understands output from diff(1), which comes in three basic flavours:

  - original diff (rarely used) which is actually a set of ed(1)
    commands to turn the old files into the new file.
  
  - context diff, as produced by "diff -c", which is more human readable,
    surrounding the changed lines with some unchanged lines from the files.
    This also has the advantage or permitting patch to cope a bit with
    mismatches. For example, if you have a diff between versions 1.21
    and 1.22, and you're trying to apply it to 1.20; if the files are
    similar enough patch can use the context lines to guess where the
    patch should go.

  - unified diff, as produced by "diff -U", which is a more compact form
    of context diff, and just as human readable, if not more so.

Make yourself a text file (eg a copy of this message). Then copy it and
modify the copy in various ways. Then compare the two using "diff -U".

A larger patch will normally be made from two complete source trees (the
old and the new) by running diff with the -r option (recursive) which
produces diffs for all the changes files.

For program version change patches, often the "old" tree will be inside
some source control system instead of being a real distinct directory
tree. Commands like "cvs diff" will generate diff output, comparing your
working area against the version inside the system.

Cheers,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

[He] is the only man I know who would regard a naked, beautiful woman staring
deep into his eyes as an uncomplaining audience for his views on the latest
version of the twm window manager.      - igb@xxxxxxxxxxxxx (Ian G Batten)


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux