DEV Community

Cover image for How to create Magento 2 git patch and apply.

How to create Magento 2 git patch and apply.

navaneethvijay profile image Navaneeth V ・1 min read

There are times where it is not possible to override an core function or a possible github fix for an issue in Magento, and you are not updating the current version to get the fix.
Times like these where git patches comes to the rescue.

The basic syntax for apply git patches
git apply <location-of-your-patch-file>

Suppose we are ought to modify the file
vendor/magento/module-customer/Block/CustomerData.php and create a custom patch.

  1. Create a copy of that file in the same location vendor/magento/module-customer/Block/CustomerDataModified.php
  2. Modify the changes in the new file and save it.
  3. At this point, the vendor folders are ignored and you want to force git to find difference between two files, so we run the command diff -u CustomerData.php CustomerDataModified.php > diff.patch This will generate a file 'diff.patch' in your root directory.

Discussion (0)

Editor guide