Working with Drupal Patch Files
1 year ago
0 comments comment

A patch is a small file which shows what was changed in a repository. It shows the new changes in an existing file, details of the new files in the current directory, file deletion details etc. A patch file can be pushed to the git repository so that it is useful in the future for updating the changes in the corresponding file.

For creating a patch file in your current git repository, make changes in your files. Now open the terminal.

For unstaged changes, type the following command,

git diff > new-changes.patch

For staged changes, you have to use git diff --cached. That is,

git diff --cached > new-changes.patch

To apply the patch, use:

git apply -v new-changes.patch

Note that, if the changes is already there when applying your patch, error message will be shown.

In, you can contribute patches to the existing core or contributed modules. For this,

  • First clone the latest version of Drupal (if it is a contributed module clone the latest code from its version control)
  • You have to create the issue with necessary issue summary in based on the fix
  • After making the changes, create a patch file based on the issue number as,
    git diff > [issue-description]-[issue-number]-[comment-number].patch
  • Update the issue with necessary comment and patch file
  • Make it's status as 'Needs Review'
  • If you want to test the patch file, add it to the queue by clicking the 'Add test' link shown below of the updated patch file

We can create and add inter diff for adding new modification for an existing patch file in an issue in, if the changes are not in the latest version of the module. For this,

  • Apply the existing patch to the latest version of module
  • Add your changes to the module
  • Create a new patch from git diff using git diff > [issue-description]-[issue-number]-[comment-number].patch
  • Create an inter diff from the old and new patches as:
    interdiff old-file.patch new-file.patch > interdiff-[issue_id]-[old_comment_number]-[new_comment_number].txt
  • Upload the newly created patch and the inter diff to the created issue in

An interdiff file tells you what new changes are there with the existing patch and newly created patch. It provides the information of the changes in patch files. So we can make the file as test free using 'do not test' option in the issues itself. So for interdiff to be ignored by the testbot, we can name the interdiff file as:


Hope this information helps in your patch creation.



on 24th January 2012 / by webmaster
By default Drupal 7 has two types of views - The Full node view and the Teaser view. This has been the case for all previous versions of Drupal. However if your requirements are different, then you might have to create a custom view that is tailored to meet your specific needs. Check out how to create a simple custom “View mode” for nodes in Drupal 7. Web Development Drupal Drupal Development Drupal 7 Leave a reply Your email address will not be published. Required fields are marker * uk (not verified) access_time 20 Aug 2019 - 15:31 Hi, It would be good if you rename the preprocess function tdbcustom_preprocess_node to CustomModule_preprocess_node Thanks, UK. webmaster access_time 20 Aug 2019 - 15:31 In reply to Hi,It would be good if you by uk (not verified) Thanks for the suggestion. Corrected the module name in the sample code. Add new comment
Leave a reply
Your email address will not be published. Required fields are marker *

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
The content of this field is kept private and will not be shown publicly.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.