1. Install the Composer Patches Module
Ensure the cweagans/composer-patches
package is installed:
composer require cweagans/composer-patches
Note for Magento Cloud Projects: If you’re using Magento Cloud, patches in the m2-hotfixes
folder are processed automatically during deployment, so the cweagans
module is not required, and patches don’t need to be referenced in composer.json
.
2. Create a Patch
Follow these steps to create a patch for files not tracked by Git (example: patching vendor/magento/module-catalog/Controller/Product/Compare.php
):
Step-by-Step Process:
1. Navigate to the Package to be Patched:
cd vendor/magento/module-catalog
2. Initialise a Temporary Git Repo:
git init . git add -A . git commit -m "Initial commit for creating a diff"
3. Make the Necessary Changes in your editor (e.g., Compare.php
).
4. Commit the Changes:
git add -A . git commit -m "Commit explaining the changes"
5. Create the Patch File:
git format-patch -1 HEAD
6. Rename and Move the Patch:
Move the patch to a dedicated patches
directory in your Magento root. Use descriptive names like github-issue-6474.patch
or MAGETWO-56699.patch
for easier reference.
7. Clean Up the Temporary Git Repository:
rm -rf .git
3. Apply the Patch in composer.json
Update composer.json
to apply the patch:
"extra": {
"patches": {
"magento/module-catalog": {
"Fix description or issue reference": "patches/github-issue-6474.patch"
}
}
}
4. Apply the Patch via Composer
Run the following to apply the patch:
composer install