Tập tành Create a Patch in Drupal 9

8th Jun 2022
Table of contents

In this blog, we are going to uncover two main questions:

  • What is a patch?
  • How to create a patch in Drupal?

So, let’s get started.

What is a patch?

Patch is a file that consists of a list of differences and is usually created with the help of the git diff command. In the Drupal community, developers make use of this patch file as a contribution to fix an issue or enhance a feature in a module, theme, or even for Drupal core.

How to create a patch in Drupal?

Here we will show you the ways of creating a Patch file:
There are 2 different ways of creating a patch file 

  • Path Independent
  • Path Dependent

Path Independent Patch

Follow these steps to create a Path Independent Patch:

  1. Create and set up a repository on GitHub specifically for creating patch files. It is best to maintain a single git repository for the patch files that you will be applying to your drupal project.
  2. Move the module/theme or core files that you need to generate patches to the newly created git repository.
  3. Make the necessary changes to a file on your local
create a patch
  1. Verify that the “git status” command shows the file that you have modified.
create a patch
  1. To generate the patch, use the following command: git diff --no-prefix [file-name] > ./file-name.patch
     
  2. The above command will generate a path-independent patch with the mentioned patch filename.
    Example: git diff --no-prefix path_independent_module.info.yml > ./updated-module-description.patch

    will generate the below file:
create a patch
  1. You can then use the independent patch file and apply it to the appropriate module(s).

Path Dependent Patch

Follow these steps to create a Path Independent Patch:

  1. Create and set up a repository on GitHub specifically for creating patch files. It is best to maintain a single git repository for the patch files that you will be applying to your drupal project.
  2. Move the module/theme or core files that you need to generate patches to the newly created git repository.
  3. Make the necessary changes to a file on your local.
create a patch
  1. Verify that the “git status” command shows the file that you have modified.
create a patch
  1. To generate the patch use the following command: git diff [file-name] > ./file-name.patch
  2. The above command will generate a path-independent patch with the mentioned patch filename.

Example:

git diff path_dependent_module.info.yml > ./updated-dependent-module-description.patch

will generate the below file:
create a patch
  1. You can then use the dependent patch file and apply it to the appropriate module(s) and make sure that the file path mentioned in the git differences is the same as in your project.
Bạn thấy bài viết này như thế nào?
0 reactions

Add new comment

Image CAPTCHA
Enter the characters shown in the image.
Câu nói tâm đắc: “Điều tuyệt với nhất trong cuộc sống là làm được những việc mà người khác tin là không thể!”

Related Articles

Master list (in progress) of how to get parts of fields for use in Twig templates. I’m always having to look these up, so I thought I’d hash them out and write them down.

Litespeed Cache là plugin WordPress dùng để kết hợp với Web Server LiteSpeed nhằm tăng tốc website WordPress của bạn gấp nhiều lần

In this article, we are going to see how some tools & libraries will make people's lives easier during the development & code review process.

In this tutorial, you will learn how to improve the custom code, theme and module, and general code development by using the pre-commit hook on git

Trước khi tìm hiểu xem PHP Code Sniffer là gì thì các bạn cần phải nắm được coding convention là gì đã.