Skip to main content

You might have seen the command "patch -p2" or an entry in composer.json when using cweagans/composer-patches like the following.

"patchLevel": {
    "drupal/core": "-p2"
}

In the command "patch -p2," the "-p2" flag specifies the patch level.

The "patch" command is used to apply changes, or patches, to source code files. The "-p" flag followed by a number tells the patch command how many directory levels to strip from the file paths mentioned in the patch file.

Here's what it means in more detail:

  • "-p0" (or simply "patch" with no "-p" flag) means that the patch file contains file paths starting from the root directory. In other words, the patch file specifies the full path to the files to be patched.

  • "-p1" means that the patch file contains file paths starting from one level above the root directory. This is often used when the patch file was created using the "diff" command with the "-u" or "-p" option.

  • "-p2" means that the patch file contains file paths starting from two levels above the root directory. This is commonly used when the patch file was generated in a directory that is two levels above the directory where the patch should be applied.

The choice of the patch level depends on how the patch file was generated and the directory structure of the project you are applying the patch to. Using the correct patch level is important to ensure that the patch is applied to the correct files with the correct paths.

So in the above example, the core folder is usually two folders inside the project root (<project_root>/docroot/core) which is why core patch level is mentioned as -p2.

 

 

x

Work

Therefore logo
80 Atlantic Ave, Toronto, ON Canada
Email: hello@therefore.ca
Call us: +1 4166405376
Linkedin

Let us know how we can help!