Last updated May 1, 2013.
If a patch has sat too long and the underlying code base has changed in the meantime, it can grow "stale." You'll know this is happening to you if you attempt to apply a patch, and get an error like so:
git apply --index 1497310-statistics_config_settings-5.patch
error: patch failed: core/modules/search/search.test:447
error: core/modules/search/search.test: patch does not apply
error: patch failed: core/modules/statistics/statistics.admin.inc:146
error: core/modules/statistics/statistics.admin.inc: patch does not apply
error: patch failed: core/modules/statistics/statistics.module:57
error: core/modules/statistics/statistics.module: patch does not apply
error: patch failed: core/modules/statistics/statistics.test:356
error: core/modules/statistics/statistics.test: patch does not applyThe automated patch testing system is also able to test whether a patch applies or not. You may see a patch on an issue with a message like "Unable to apply patch [patchname]. Unable to apply patch…" beside it:
Instructions for "re-rolling" a new patch that applies cleanly
- Check out the latest 8.x code in your Drupal core repository.
git checkout 8.x
git pull --rebase - Unless otherwise specified in the issue comments, always reroll the most recent patch found on the issue. You can find the latest patch by clicking the 'Most recent attachment' link on the top right of the page.

Note the date of the last comment in the issue with a patch attached.
- Run the
git logcommand with that date, in order to figure out a commit where the patch applied cleanly.git log --before="March 30, 2012"commit 992692441ea6f315b85606c7d117f8a94226d15f
Author: Jennifer Hodgdon <yahgrp@poplarware.com>
Date: Fri Mar 30 14:45:46 2012 -0700
Issue #1440834 by nmudgal: Add clarity and information to docs for hook_field_delete/update/insert
commit e577cff7cc0786044faf39cb2dfdf5813893f2db
Author: Dries <dries@buytaert.net>
Date: Fri Mar 30 12:17:26 2012 -0400
- Patch #1309394 by effulgentsia, sun: process #autocomplete_path() for all form elements; remove custom/duplicated code from theme_textfield().
commit 642f91d112fbee14a34c51b9637cfc9964e6ef49
... - Take the first few characters of the first commit hash you see there (in this case,
992692441) and checkout the code from that commit:git checkout -b cmi-statistics 992692441Switched to a new branch 'cmi-statistics' - Try applying the patch to test if it works:
git apply --index 1497310-statistics_config_settings-5.patch(no output)If you see no output, you're good to go. If you get similar "patch does not apply" errors, delete your current branch and repeat the previous step with an earlier commit hash (e.g.
e577cff7ccin this case). - Commit the patch's changes to your local branch.
git commit -m "Applying patch from http://drupal.org/node/1497310#comment-5804956"[cmi-statistics 00329ef] Applying patch from http://drupal.org/node/1497310#comment-5804956
7 files changed, 99 insertions(+), 66 deletions(-)
create mode 100644 core/modules/statistics/config/statistics.settings.xml - Now, attempt to pull in all of the changes that have happened since the commit you branched from. Any rows that begin with "CONFLICT" are the ones you'll need to sort out in order for the patch to apply cleanly.
git rebase 8.xFirst, rewinding head to replay your work on top of it...
Applying: patch
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): core/modules/statistics/statistics.test deleted in HEAD and modified in patch. Version patch of core/modules/statistics/statistics.test left in tree.
Auto-merging core/modules/statistics/statistics.module
CONFLICT (content): Merge conflict in core/modules/statistics/statistics.module
Auto-merging core/modules/statistics/statistics.install
CONFLICT (content): Merge conflict in core/modules/statistics/statistics.install
Auto-merging core/modules/statistics/statistics.admin.inc
CONFLICT (content): Merge conflict in core/modules/statistics/statistics.admin.inc
CONFLICT (modify/delete): core/modules/search/search.test deleted in HEAD and modified in patch. Version patch of core/modules/search/search.test left in tree.
Failed to merge in the changes.
Patch failed at 0001 patch
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To check out the original branch and stop rebasing run "git rebase --abort". - Go through each of the files listed as having conflicts, and look for a line like
<<<<<<< HEAD. For example:open core/modules/statistics/statistics.module...
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
<<<<<<< HEAD
if (variable_get('statistics_enable_access_log', 0)) {
=======
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
// Get the configuration for the settings.
$config = config('statistics.settings');
$statistics_count_content_views = $config->get('statistics_count_content_views');
$statistics_enable_access_log = $config->get('statistics_enable_access_log');
if (!empty($statistics_count_content_views)) {
// We are counting content views.
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == NULL) {
// A node has been viewed, so update the node's counters.
db_merge('node_counter')
->key(array('nid' => arg(1)))
->fields(array(
'daycount' => 1,
'totalcount' => 1,
'timestamp' => REQUEST_TIME,
))
->expression('daycount', 'daycount + 1')
->expression('totalcount', 'totalcount + 1')
->execute();
}
}
if (!empty($statistics_enable_access_log)) {
>>>>>>> your-branch-name
...Everything above the
=======is from the "clean" upstream version. Everything below the=======is found in the patch you are rerolling. In general, you want to keep what's in the clean upstream version, and then modify it to follow the changed behavior from the patch. This ensures that any other changes that have been made to the upstream version not affecting your patch do not accidentally get undone. - Edit the file until it looks correct, making sure to remove the special conflict marker lines.
For example:
...
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
if (config('statistics.settings')->get('statistics_enable_access_log')) {
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
... - Stage your changes with
git add. (Be careful not to accidentally stage files that have been removed in HEAD. Usegit rmfor those if necessary.) - Run
git rebase --continueand repeat the previous steps until there are no conflicts left to resolve. - Finally, create your patch, by diffing your local branch (cmi-statistics) against the upstream branch:
git diff 8.x cmi-statistics > cmi-statistics.patch - Test your patch by applying it to the upstream branch.
git checkout 8.xSwitched to branch '8.x'git apply --index cmi-statistics.patch(no output) - If all looks well, upload it to the issue and mark it back to "needs review!" :) Congratulations! You've just re-rolled a patch!
| Attachment | Size |
|---|---|
| reroll-date.png | 60.99 KB |
| reroll-latest-attachment.png | 13.17 KB |
| reroll-unable-to-apply.png | 42.85 KB |

