Let’s say you want to apply a patch from a third-party module installed via composer for a controller. Please make sure that you have this part in the composer.json file:
"extra": {
"magento-force": true,
"composer-exit-on-patch-failure": true,
"patches": {
"vendorname/module-somerandomname": {
"Description here": "patches/my_patch_name.patch"
}
}
},
Assuming that your vendor folder is in the .gitignore file, you can still do:
git add -f vendor/vendor/module/Controller/Myfile.php
Apply your changes to the Myfile.php
Now run the following commands below.
git diff vendor/vendor/module/Controller/Myfile.php > patches/my_patch_name.patch
git reset HEAD vendor/vendor/module/Controller/Myfile.php
Now run the command composer install