Ways to manage patches in project

If you are hacking the contributed modules, then you are doing it wrong.Here are the strategies that you can take to maintain the patches in the project.It depends on the structure of the project.

Managing the patches via composer

If you're using the Composer(It is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage install/update them for you.) for managing dependencies then you're saving ton of your time to update and maintain your software.All the contributed/custom patches are being maintained by composer using the composer-patches plugin and there's a few command to maintain it.

How to patch a contributed project : Here's an example of applying the patch to a contributed project using an external patch file.

{
  "require": {
    "cweagans/composer-patches": "~1.0",
    "drupal/drupal": "~8.2"
  },
  "config": {
    "preferred-install": "source"
  },
  "extra": {
    "patches-file": "local/path/to/your/composer.patches.json"
  }
}

Then your composer.patches.json should look like this:

{
  "patches": {
    "vendor/project": {
      "Patch title": "http://example.com/url/to/patch.patch"
    }
  }
}

See more examples of applying and managing patches here https://github.com/cweagans/composer-patches

Managing the patches manually

All modifications to contributed projects must be performed via a patch.Patches that can be contributed on Drupal.org should be contributed there. Please follow Drupal.org's patch naming conventions when creating patches.

Patches that cannot be contributed publicly are extremely rare. In the unlikely event that such a change must be committed, all project-specific patches should reside in this directory. This ensures one consistent place for patches and avoids accidental patch deletion. Patches should be stored in sub-directories based on project name being patched.
Examples:

- /patches/drupal/some_patch-1234-1.patch
- /patches/ctools/another_patch_name-9876-12.patch

Patch documentation should be in the following format:


    ## module name

    * brief description
      * issue link (if exists)
      * patch file location

Example:

    ## views

    * Improve the display of the custom URL engine textarea.
      * http://drupal.org/node/809250
      * https://www.drupal.org/files/issues/xmlsitemap-improve-url-engine-textarea-809250-11.patch
      * patches/xmlsitemap/xmlsitemap-improve-url-engine-textarea-809250-11.patch

Steps to apply patches :

    1) Search the issue queue for the project to see if a patch already exists
    2) Download the patch (or create it if required), then add it to this folder
    3) Follow the instructions above to document the patch
    4) Take the patch file and move it to the directory of the module to be patched
    5) cd into that directory
    6) apply the patch, typically using `patch -p1 < [filename]
    7) Remove the patch file from the module folder
    8) Commit the patched module
    9) If you created the patch, add it to the project issue queue so that it might be included in a future release

Yoast SEO for Drupal

    * Bad grammar in node edit form.
      * https://www.drupal.org/node/2810713
      * https://www.drupal.org/files/issues/fix-issue-2810713-4.patch
      * patches/yoast_seo/fix-issue-2810713-4.patch

See the Sample Readme.md how to manage the patches manually.