Why is this patch applied with fuzz of 1, and with error 0?

$ vim patch
Index: toPatch
===================================================================
--- toPatch
+++ toPatch
@@ -2,4 +2,4 @@
  */
-final public class XMLWriter {
+public class XMLWriter {

$ vim toPatch
 */
final public class XMLWriter {

  public static float CURRENT_VERSION=2.2f;
    $ patch -p0 -ui patch
patching file toPatch
Hunk #1 succeeded at 1 with fuzz 2 (offset -1 lines).

Why fluff and line offset? This is a demo trying to understand diff and patch, as tools sometimes / often do not work as expected.

+3
source share
2 answers

The patch does some basic consistency checking for diff and your file, and if these checks fail, you get an offset or fuzz.

You have a -1 offset, since the patch expects the contents of matching lines 2-4 of your file. However, in your file these are lines 1-3.

fuzz > 0, ( */) ( */). - , .

, fuzz = 2, 1. , ? , -?

+15

patch ( @@) .

  • @xofon, , 2, 1
  • 3 4, 3 patch 3 patch .
  • */ . patch 2 , , - + . ( 1)

, patch

$ cat patch
--- toPatch
+++ toPatch
@@ -1,3 +1,3 @@
  */
-final public class XMLWriter {
+public class XMLWriter {
   public static float CURRENT_VERSION=2.2f;

toPatch

$ cat toPatch
 */
final public class XMLWriter {
  public static float CURRENT_VERSION=2.2f;

fuzz...

$ patch -p0 -ui patch
patching file toPatch
+2

All Articles