Patch

From Devpit
Jump to: navigation, search

The path stripping directive '-p'

The -p argument directs patch to strip a certain number of leading directories from a diff generated path when applying the patch to the current working directory. The -p directive is immediately followed by a number representing the number of leading directories to strip when applying the patch. For instance, given the following diff line snippet from e.patch,

--- linux-2.6.15-rc5/include/asm-powerpc/hvconsole.h      2005-12-19 10:49:35.136173560 -0500
+++ linux-2.6.15-rc5-new/include/asm-powerpc/hvconsole.h  2005-12-19 10:57:35.101154584 -0500

And given the following directory structure,

«user@host»:~/kernels/linux-2.6.15-rc5§ ls
arch     Documentation  init    MAINTAINERS  REPORTING-BUGS
block    drivers        ipc     Makefile     scripts
COPYING  e.patch        Kbuild  mm           security
CREDITS  fs             kernel  net          sound
crypto   include        lib     README       usr

The following 'patch' invocation:

«user@host»:~/kernels/linux-2.6.15-rc5§ patch -p1 < example.patch

will strip the leading directory linux-2.6.15-rc5-new from the diff string "linux-2.6.15-rc5-new/include/asm-powerpc/hvconsole.h" and apply the patch to the local include/ directory.

The Linux Kernel Mailing List and all other related Linux related mailing lists require that patches be created with a leading directory, such that patch -p1 applies the patch when the current working directory is in the kernel tree base directory, as indicated by the example.

Test apply with '--dry-run'

The --dry-run directive can be passed to the patch application on invocation to direct patch to simulate the apply. This is useful to determine whether the patch will apply cleanly to the directory tree presently in the current directory. It is invoked as follows:

«user@host»:~/kernels/linux-2.6.15-rc5§ patch --dry-run -p1 < example.patch