Downloading a patch file

Last updated on
27 April 2026
Do not use the URL to the GitLab MR patch file directly in your site. The contents of merge requests patches change as commits are pushed.

Downloading a patch or diff file

From the Drupal.org issue page

You can download a patch file directly from an issue.  Under the "Issue fork" heading below the issue summary, above Comments, click the plain diff link.

Larger version of plain diff screenshot on Drupal issue

From the GitLab Merge Request UI

On the associated merge request on GitLab, use the Plain diff option in the Code menu:

Larger version of merge request patch download screenshot

From command line

You can also get a patch file of diff file for any merge request by appending .patch or .diff to the end of the merge request URL. For example, if this is your merge request:

https://git.drupalcode.org/project/drupalorg/-/merge_requests/17

add '.patch' to get a patch file

https://git.drupalcode.org/project/drupalorg/-/merge_requests/17.patch

or add '.diff' to get a diff file.

https://git.drupalcode.org/project/drupalorg/-/merge_requests/17.diff

to get a URL to download the patch. 

From GitLab Email Patches option

To get a patch file for a single commit navigate to the commit page, click on Options and select Email Patches:

patch file from gitlab

To get the patch for a Merge Request that consists of several commits navigate to the overview of the MR, click on the "arrow down" icon and then click Email Patches:

patch file for a gitlab merge request

.patch versus .diff

The patch file resulting from using the .patch URL has separate changes for each commit. 

The diff file resulting from the .diff URL is simpler as it consolidates all the changes. If the MR is long and has several changes to the same files, including file renames, patch files downloaded from .patch URLs may not be usable.

Patch files are also useful if you use bash patch -p1 < file or git apply patch

Use local patch files with Composer

The contents of merge request patches on GitLab will change as commits are pushed!

It's strongly recommended to lock the patch file versions on production sites. Not doing this is a security risk and can otherwise break your site. To keep your site secure you must do one of the following;

1) Download the patch file to your site codebase and add the path to that local file to your site composer.json file.

2) Use version 2 of cweagans/composer-patches. Use the patches.lock.json file in conjunction with declaring your patch checksums in your patches.json file. composer-patches version 2 aborts noisily if it fetches a patch which does not match the checksum specified in the patches.json file.

If you use the URL to the GitLab MR patch file directly, your codebase will change without warning, as work on the merge request continues. Every time composer update runs on your site the latest patch file, with new changes, is automatically applied to your site.

Read the documentation for composer-patches.

Creating a patch file of a Merge Request for an older stable release

Most merge requests target the development version. not a stable production version.

Therefor, the patch may or may not apply to the version you are using. If there is a conflict you need to git cherry-pick all the commit IDs in the branch into the target version of Drupal and resolve the conflicts. You can also rebase to a new base branch.

For example:

git clone DRUPAL-GIT-REPO folder-name
cd folder-name
git remote add drupal-ISSUE-NUMBER https://git.drupalcode.org/issue/drupal-ISSUE-NUMBER.git
git fetch drupal-ISSUE-NUMBER
git checkout -b PATCH-BRANCH-NAME refs/tags/STABLE_RELEASE
git cherry-pick FIRST-COMMIT-ID-IN-BRANCH..LAST-COMMIT-ID-IN-BRANCH
git diff refs/tags/STABLE_RELEASE > PATCH-FILENAME-HERE.patch

Note here that everything in all capital letters should be replaced.

Help improve this page

Page status: No known problems

You can: