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.
How to apply a patch?
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
How to apply a custom patch on Magento Cloud?

Please make sure to test all patches in a pre-production environment. For Adobe Commerce on cloud infrastructure, you can create new branches with the magento-cloud environment:branch <branch-name> CLI command.
To apply a custom patch on a Cloud environment, please follow the steps below.
Step 1. In the project root, create a directory called m2-hotfixes
if it does not exist. Please run the following command:
mkdir m2-hotfixes
Step 2. Copy the patch file to the /m2-hotfixes
directory. All patch file names must end with the .patch
extension
Step 3. Add, commit, and push code changes:
git add -A
git commit -m "Apply patch"
git push origin
How to apply a patch to avoid overwriting modified files when updating the module?
Magento allows adding patches to Composer in order to prevent modifications from being overwritten while updating the extension. To apply the patch using Composer, follow the guidelines below.

Please note that this instruction works only for patches applied to the vendor
folder. Patches that are applied to the app
folder can't be added to Composer.
Step 1. Navigate to the directory of your project via CLI.
Step 2. Run the below command to install package cweagans/composer-patches
that allows you to patch modules:
composer require cweagans/composer-patches
Step 3. Edit the composer.json
file and add the “extra” section with the subsequent information:
- Module name, which the patch is applied to:
⇾ "amasty/shopby"
- Title. We recommend specifying the title that contains the ticket ID where the patch was provided and a mini-description of the modification:
⇾ "390600: ILN can be enabled per store view"
- Path to patch. Usually, such patches are added to the "patches" folder in the root Magento:
⇾ "patches/390600.diff"
The expected outcome should resemble the following example:
"extra": {
"composer-exit-on-patch-failure": true,
"patches": {
"amasty/shopby": {
"390600: ILN can be enabled per store view": "patches/390600.diff"
}
}
}
If a patch affects multiple modules, you must create multiple patch files targeting multiple modules.
Step 4. Apply the patch with the command below (use the -v
option only if you want to see debugging information):
composer -v install
Step 5. Update the composer.lock
file. The lock file tracks which patches have been applied to each Composer package in an object.
composer update --lock
How to revert a patch?
Step 1. Place the .diff or .patch file to the root directory of Magento or the corresponding module, where the patch was previously applied. The location depends on the instructions received from the Support Team or on the patch content.
Step 2. Connect to the server via CLI.
Step 3. Navigate to the directory, where the patch was uploaded.
Step 4. From this directory, run the command below, where PATCHFILENAME is the name of the patch file you’ve added.
patch -R -p1 < PATCHFILENAME
If Git is used on your server, it makes sense to use the next command instead:
git apply -R PATCHFILENAME
Step 5. Run the commands suggested by the Support Team to make sure that reverted changes are detected by Magento.