Last updated September 30, 2015.

What is an interdiff and why it is useful?

An interdiff is a text file in patch format that describes the changes between two versions of a patch. Using interdiffs is a best practice that saves time and reduces tedium for reviewers by allowing them to focus on just the changes introduced in patch iterations. You should supply one whenever you update a significant patch in the issue queues (it will be ignored by the Testbots, so make sure that you always upload the full patch too).


Create interdiff using git

Follow these steps to create an interdiff in your local Git repository:

  1. Always pull the latest changes.
    git pull --rebase
  2. Create a branch for the old patch.
    git checkout -b [issue_id]-[old_comment_number]
  3. Download the old version of the patch you wish to update and apply it to your local git repository.
    git apply --index patchname.patch
  4. Commit the changes from the old patch.
    git commit -m "[issue_id]-[old_comment_number]"
  5. Depending on how you like to work, you now have a choice between two options.
    1. If you do not yet have a new patch created, you can now create a new branch.
      git checkout -b [issue_id]-[new_comment_number]
    2. Otherwise, let's go back to the mainline branch and create a new branch to patch from.
      git checkout 8.0.x
      git checkout -b [issue_id]-[new_comment_number]
  6. Make your changes on the new branch (e.g. apply your new patch), then commit the changes.
    git commit -m "[issue_id]-[new_comment_number]"
  7. Generate the interdiff by comparing the current (new) branch against the old branch.
    git diff [issue_id]-[old_comment_number] > interdiff-[issue_id]-[old_comment_number]-[new_comment_number].txt
  8. Upload the interdiff to the issue as an attachment along with your updated patch. You can create the updated patch easily at this point with:
    git diff 8.0.x > [issue_id]-[new_comment_number].patch

Create interdiff using patchutils

Note: You can also create interdiffs by using the interdiff command that is included with patchutils.:

interdiff old.patch new.patch > interdiff-[issue_id]-[old_comment_number]-[new_comment_number].txt

For Mac-users: the easiest way to get the interdiff command available is by using Homebrew with the following command: brew install patchutils

For Debian-ish Linux-users: Install it with: sudo apt-get install patchutils

Why use interdiff and not just simply diff two patches?

An interdiff tells you whether lines removed in the second patch were added in the first patch, and similarly, whether lines added in the second patch were removed in the first patch. Simply diffing the two commits does not provide this information, forcing the reviewer to consult the original patch or current source to determine whether this is the case.

Make interdiff ignored by the testbot

If you use .diff extension for interdiff add do-not-test before the .diff. Final pattern will be interdiff-[issue_id]-[old_comment_number]-[new_comment_number]-do-not-test.diff.
For example: interdiff-999999-91-92-do-not-test.diff

What am I supposed to do with another users interdiff?

Nothing, other than read it. Interdiffs are for developers and reviewers working on a patch, not for sitebuilders using the patches. They help to easily see the differences between two versions of a patch.
It is easy to tell which files are patches you can use and which are not by the file extension. The real patches end in .patch and they are the only ones you should try to apply to your site.

More information

See also Interdiffs! How to make them, and why they are your friends.


Codenator’s picture

When I try after step 5 apply new.patch I got an errors
p.s. I work on windows

Alan D.’s picture

If you already have the patch created, try switching back to the main branch and creating the new branch from there and then applying the patch. Otherwise you will get conflicts trying to apply the updated patch to the updated code (from the original patch).

pfrenssen’s picture

You can create an interdiff between two patches without switching to a different branch by doing some git trickery:

Easy mode: git revert HEAD --no-commit

  1. Apply and commit the first patch.
    $ git apply --index 123456-1.patch
    $ git commit -m "Patch 123456-1."
  2. Revert the patch without committing it. This will just update the working directory.
    $ git revert HEAD --no-commit
  3. Now we can apply and commit our second patch and generate the interdiff.
    $ git apply --index 123456-2.patch
    $ git commit -m "Patch 123456-2."
    $ git show > interdiff.txt

Hard mode: using staging area as temporary storage

If you want to train your git-fu, here is another interesting way of generating interdiffs:

  1. Apply and commit the first patch.
    $ git apply --index 123456-1.patch
    $ git commit -m "Patch 1."
  2. Reset the staging area to the previous commit without moving HEAD. If a path is specified to the git reset command it will not switch branches. By using a period for the path we instruct to reset all files.
    $ git reset HEAD^ .
  3. Our HEAD still points to the current commit, and our staging area has been reset to the previous commit. Git has not touched the actual files in the working directory, so the files still have the first patch applied. The staging area contains the code we want, so we need a way to revert the working directory without losing the staging area. We can use the stash for this.
    $ git stash --keep-index
  4. Now we can apply and commit our second patch and generate the interdiff.
    $ git apply --index 123456-2.patch
    $ git commit -m "Patch 123456-2."
    $ git diff HEAD^ > interdiff.txt
  5. You might want to get rid of the stashed code:
    $ git stash drop
rooby’s picture

A very quick alternative that works well in some situations is this.
This is to get a patch from make some changes and create a new patch and interdiff.

I have a drupal core checked out at latest dev that I use to create patches and I find it works well if you have been working on changes to a patch on an existing website and want to quickly create a new patch with your changes.

  1. git pull
  2. wget old-patch-name.patch
  3. git apply --index old-patch-name.patch
  4. rm old-patch-name.patch
  5. git add -A
  6. make new changes
  7. git diff > interdiff-[issue_id]-[old_comment_number]-[new_comment_number].txt
  8. mv interdiff-[issue_id]-[old_comment_number]-[new_comment_number].txt /somewhere/else/
  9. git add -A
  10. git diff --staged > [project_name]-[short-description]-[issue-number]-[comment-number]-[drupal-version].patch
  11. mv [project_name]-[short-description]-[issue-number]-[comment-number]-[drupal-version].patch /somewhere/else/
  12. git reset --hard