How to apply a patch?

How to apply a patch?

A “patch” is a compact representation of the differences between files, intended for use with line-oriented text files. It describes how to turn one file into another, and is asymmetric: the patch from file1 to file2 is not the same as the patch for the other direction. 

Patches are intended to modify the files - applying the patches adds and/or removes the lines of code to/from the original file. This way, the original file is changed having preserved the main content.

The patch format uses context as well as line numbers to locate differing file regions, so that a patch can often be applied to a somewhat earlier or later version of the first file than the one from which it was derived, as long as the applying program can still locate the context of the change.


Patch application

Step 1. Place the diff file to the root directory of the corresponding module.

app/code/Amasty/[Extension Name] - the path to the root folder of the extensions installed manually;
vendor/amasty/[extension-name] - the path to the extensions installed via composer.
      
Step 2. Connect to the server via CLI.
     
Step 3. Navigate to the folder with the patch. From this directory, run the command below, where PATCHFILENAME is the name of the diff file you’ve added.

git apply  PATCHFILENAME

The command might return an error reporting that command ‘git’ doesn’t exist. In this case, please use the alternative command:

patch -p1 < PATCHFILENAME