How to create Magento 2 git patch and apply?

There are times where it is not possible to override a core function or a possible GitHub fix for an issue in Magento or Override third party library, and you are not updating the current version to get the fix.

Times like these where git patches come to the rescue.

Step 1: File to changed should be added to the git

git add -f vendor/dotmailer/dotmailer-magento2-extension/Api/Data/CouponAttributeInterface.php

Step 2: Then make the changes in the core file

Step 3: After making the changes run below command, This creates the patch in m2-hotfixes

git diff vendor/dotmailer/dotmailer-magento2-extension/Api/Data/CouponAttributeInterface.php > m2-hotfixes/webapi-fix.patch

Step4: Finally apply the patch

git apply m2-hotfixes/webapi-fix.patch

Leave a Reply