Jump to content

Help:Diff

Page semi-protected
From Wikipedia, the free encyclopedia

A diff (from the word "difference") is a presentation of the difference between one version and another of a Wikipedia page. A particular version of a page is called a "revision". Each revision has a date and time of creation, and an author, which can be seen in the page history. Clicking a "diff" link in a page's history, or selecting two revisions with the radio controls and clicking on the "compare selected revisions" button, will display the diff between the two revisions. (Clicking on the timestamp link in the page history will alternatively display the page as it was at that point in time).

Links to diffs are found on various special pages other than page histories, including the User contributions page of every user, Recent changes, Related changes, and watchlists.

Using the history of a page, it is possible to generate a diff between any two versions – select the left radio button for the older version, the right radio button for the newer version, and click Compare selected revisions.

While editing a page, the Show changes button displays the changes you are about to make. The diff is also shown during an edit conflict.

Edit summary (Briefly describe your changes)
 

By publishing changes, you agree to the Terms of Use, and you irrevocably agree to release your contribution under the CC BY-SA 4.0 License and the GFDL. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.

Publish changes Show preview Show changes Cancel

How it looks

This example shows what a diff page looks like (excluding any page preview that may normally appear at the bottom; some of the links are dummies). The older revision is presented on the left, while the newer revision is presented on the right.

(Edit summaries in diffs are great)
m (correction, + MediaWiki User's Guide)
 
Line 8: Line 8:
  For sysops and those with the rollback flag, a [[en:Wikipedia:revert|rollback]] button is shown allowing them to revert from the new version to the old one.   For sysops and those with the rollback flag, a [[en:Wikipedia:revert|rollback]] button is shown allowing them to revert from the new version to the old one.
This is only shown when viewing the diff between the current version and the one immediately preceding it. + This is only shown when viewing the diff between the recent version of a page and the last version by an author other than the one of the most current version.
  This example shows the top of the diff page, with the links described above.   This example shows the top of the diff page, with the links described above.
Line 25: Line 25:
  </table>   </table>
+ [[MediaWiki User's Guide]]
+

Explanation of colours

Unchanged paragraphs appear with a subtle grey background and a grey border. (Note that not all paragraphs are shown; only some of those surrounding the changes). Modified, moved, deleted, and inserted paragraphs all have a transparent background, a coloured border, and a symbol to the left of them. Such paragraphs on the left (from the older version) are given a yellow border colour, and carry a minus symbol (−), with the exception of moved paragraphs which carry a right-facing arrow symbol (↪). Similarly, such paragraphs on the right (from the newer version) are given a blue border colour and carry a plus symbol (+), unless it's a moved paragraph, in which case it carries a left-facing arrow symbol (↩). Note that these arrow symbols can be clicked on to jump between the moved-to and moved-from locations.

When a paragraph is recognised as having been modified or moved, any text deleted from the original paragraph is highlighted in bold-yellow on the left, and any text inserted is highlighted in bold-blue on the right. Where an old paragraph is deleted entirely, or an entirely new paragraph is inserted, no such bold-colour highlighting is done to its entire text. New, deleted, and moved paragraphs will be seen to have an empty entry opposite them.

Beware that diff algorithms are not perfect. Presenting perfect diffs for every possible combination of changes is difficult, with compromises often having to be made. Consequently sometimes changes may fail to be recognised as a modification or move of an existing paragraph, and thus appearing instead as a pair of deleted and inserted paragraphs.

Colour key
Old version New version
Unchanged paragraph Unchanged paragraph
Modified paragraph, with text removed + Modified paragraph, with text added
Moved paragraph  
Deleted paragraph  
  + New paragraph
  Moved paragraph

The links "Revision as of date" link to each version. If the newer version is the latest one, the link will be to the usual page and the wording will be "Current revision (date)" instead.

The "(edit)" link will take you to the page for editing that version. You may be warned that you are editing an out-of-date revision; if you ignore this and continue, you will revert all the edits made since that revision.

The "(undo)" link on the newer revision's side will revert that specific edit. When you click the link, you can check the diff page of the edit you are going to make, and the edit summary will be automatically filled in with the phrase of MediaWiki:undo-summary (Undid revision $1 by $2 (talk)). This summary can be edited before you submit your edit. When you are undoing several edits at once, the auto-summary may not work. Though the link exists on all diff pages, it does not function when the revisions conflict. Often, versions older than the current one cannot be undone in this way. If it does not work, you will be told that the edit could not be undone and end up on the regular editing page of the current version.

The "(thank)" link is only displayed when both the viewer and editor are registered users. It can be used to thank the editor.

Below that are links to the user page and talk page of each user who edited the older or the newer versions. Links to the users' contribution lists are also shown. For administrators and rollbackers, a "[rollback]" button also appears where applicable, allowing them to revert all the edits made by that user.

Then the edit summaries are shown in parentheses. If the user has used links in their edit summary, these act as links on the diff page as well. If the editor marked the edit as a minor edit, m appears before the summary.

The "Previous edit" and "Next edit" links lead to earlier or later diffs. When you are viewing the diff between two non-consecutive versions of a page, you will also see the message "(x intermediate revisions not shown.)".

After the table of differences, the latest of the two compared versions is shown fully, unless you have specified in your preferences that this is not to be done.

Direction of comparison

Typically the revision shown on the left of a diff page will be the older of the two revisions. Technically however, strictly speaking this may not necessarily always be the case. For prev, next, and cur forms of diffs, or diffs resulting from the radio controls in a page's history, the older of the two revisions is indeed always going to be on the left. However, things can get less certain when it comes to user generated diff links, since it's easy to make mistakes, and the behaviour of the diff page may be surprising.

As discussed later in the linking section, fundamentally, the diff page shows a difference with respect to a base revision specified via an oldid parameter. When the diff URL specifies another revision ID to be compared against the specified base revision, the diff page always assumes that the base will be the older of the two revisions and thus always places it on the left. (Or at least this is the case in early September 2026). Consequently, diff links should always be constructed with the older revision ID (the smaller number) specified as the base ID, and if this is not done so, then the resulting diff may appear backwards and confusing. You can spot such a situation either by the base revision ID in the URL being a larger number than the other ID, or more simply by the date of the revision on the right being older than the one on the left. You can correct it simply by swapping the two IDs in the URL.

Linking to a diff

If you find yourself needing to provide a link to a diff, under certain circumstances it may suffice to simply copy and paste the URL of the diff page (which of course can be done by either copying the URL from the address bar in your web browser, or right clicking on a diff link and selecting 'copy link'). However, when providing a diff link within wikipedia pages (for example in a talk page), it is preferable to use one of the alternatives discussed later, which are both neater, and make links work on our mobile site.[clarification needed]

Use of diff links does not necessitate understanding of them, but understanding them may aid you in producing correct links that show what you intended for them to show, especially with the preferred link construction methods to be used within wikipedia, and it's more simple than you might realise.

There are three key parameters relevant to diffs:

  • oldid: This is used to specify the unique ID of a particular revision of a page to base the diff on.
  • diff: This is used to specify what to compare the specified revision with. This can contain values of either prev, next, cur, or another revision ID.
  • diffonly: This is optionally used to control whether or not a preview of the page is shown beneath the diff. By default a preview is shown. This parameter can be added with a value of 1 if the preview is not wanted.

The values prev (meaning previous) and next for the diff parameter are used to compare the revision specified in oldid with the singular revision that either preceded it, or succeeded it, respectively. I.e. prev compares the revision with one revision backwards in time, while next compares with one revision forward in time. In the prev case, the specified revision is shown on the right hand side of the page, while the opposite is true for next. Note that if no previous or next revision exists, respectively, then the diff will simply indicate that no difference exists. If diff is set to a revision ID, while no oldid param is provided, then this is treated as though the ID had been specified in oldid and diff was set to prev. (Note that alternatively, if oldid is specified alone, without a diff parameter, then the old revision of the page will be presented rather than a diff).

A diff is not limited to comparing just a pair of revisions that are directly adjacent in history; it can compare any singular revision with any other. When diff is set to cur (meaning current), then the revision specified with oldid is compared with the very latest (current) revision of the page. When diff is instead set to a revision ID, then similarly the revision specified with oldid is compared with the revision specified by diff. Note that in the latter case the diff revision is expected to be a newer ID than that specified by oldid. If this expectation is not honoured, then the presented diff may appear confusing, since the revision specified by oldid is presented on the left hand side of the page even if the diff ID were actually older, resulting in a presentation that appears backwards. Note that if both revision IDs are the same, then the diff will state that no difference exists.

Note that diff comparisons are not even limited to revisions from the same page. A revision ID from a different page can be specified in diff and the diff will simply present a comparison of the content of the two pages as they were at those two points in time. The page name displayed at the top of the diff will be shown in the form Page-name-A and Page-name-B in such a scenario.

If either oldid or diff is set to a revision ID that does not exist, then an error will be displayed.

For linking to a diff from outside of wikipedia, or where otherwise permissible within wikipedia, full links (URLs) take the example forms below. When exploring page history these can be copied directly from the address bar in a web browser, or from right clicking on a diff link and selecting 'copy link'. Note that, as mentioned above, within wikipedia it's preferable to avoid full URLs whenever possible, using the alternative internal linking methods discussed below instead.

Beware that if/when using a full URL within wikipedia, if you just paste the raw link, the full URL will be used as the display text for the link (e.g. https://en.wikipedia.org/w/index.php?title=apple). These can be long and unwieldy. If you put a pair of square brackets around it, like [https://en.wikipedia.org/w/index.php?title=apple], then the displayed text will appear like . If you also include a space and then some text inside the brackets, after the URL, then that text will replace the number as a display label for the link. For example, [https://en.wikipedia.org/w/index.php?title=apple the apple article] becomes the apple article.

The following examples use 54321 as an example oldid revision ID, and 123456789 as an example newer diff revision ID. Note that while many wikipedia URLs include a title parameter to specify the name of a page, like in the previous paragraph, and while this often can be found within diff URLs, this isn't strictly required to be present in a diff URL, and is excluded from them in the following examples.

Examples
URLTarget
https://en.wikipedia.org/w/index.php?oldid=54321&diff=prevDiff comparing revision 54321 with the one that immediately preceded it.
https://en.wikipedia.org/w/index.php?oldid=54321&diff=nextDiff comparing revision 54321 with the one that immediately succeeded it.
https://en.wikipedia.org/w/index.php?oldid=54321&diff=curDiff comparing revision 54321 with the latest (current) revision.
https://en.wikipedia.org/w/index.php?oldid=54321&diff=123456789Diff comparing revision 54321 with (presumed newer) revision 123456789.
https://en.wikipedia.org/w/index.php?diff=54321Same diff as the first example (prev based), but in the simpler form that relies upon prev being considered the default, and punting the revision ID into diff rather than oldid since the latter on its own creates a link to view the revision rather than see a diff.
https://en.wikipedia.org/w/index.php?diff=54321&diffonly=1Same as the previous example, except opting into no page preview being shown.
[https://en.wikipedia.org/w/index.php?oldid=54321&diff=prev]Same as the first example, but placed within square brackets for neater display. (Appears like ).
[https://en.wikipedia.org/w/index.php?oldid=54321&diff=prev my diff link]Same as the first example, but placed within square brackets for neater display, with custom display label. (Appears like my diff link).

Diff links can be created within wikipedia using the special [[Special:Diff/oldid]] and [[Special:Diff/oldid/diff]] link formats. Use of this form, or the {{diff}} template discussed below, should be used whenever possible within wikipedia, for the reasons mentioned earlier. Note that unlike {{diff}}, this form works within edit summaries. Note also that, as with other double-square-bracket link forms, you can add a pipe (|) character followed by some text, before the closing pair of brackets, to specify a nicer display label for the link (i.e. like [[Special:Diff/oldid/diff|my diff link]]).

Examples
LinkTarget
[[Special:Diff/54321]]Same as the next example.
[[Special:Diff/54321/prev]]Diff comparing revision 54321 with the one that immediately preceded it.
[[Special:Diff/54321/next]]Diff comparing revision 54321 with the one that immediately succeeded it.
[[Special:Diff/54321/cur]]Diff comparing revision 54321 with the latest (current) revision.
[[Special:Diff/54321/123456789]]Diff comparing revision 54321 with (presumed newer) revision 123456789.
[[Special:Diff/54321|my diff link]]A variation of the first example using a nice label. (Will appear like my diff link instead of Special:Diff/54321).

As demonstrated in the examples, when a URL has diff set to prev, or where diff specifies a revision ID and oldid is unspecified, the singular revision ID on its own suffices within the special link. Otherwise, when copying parameters from a URL, care needs to be taken to not just copy the oldid revision ID, but the accompanying next, cur, or revision ID detail from the diff parameter too, else the resulting diff might not be what you expect.

The {{Diff}} template

The {{diff}} template provides an alternative to the special diff links just described. These may appear cleaner, and may be easier to memorise, however beware that they do not work within edit summaries (templates are not expanded within edit summaries, instead just appearing as written).

The general syntax is:

{{tlx|Diff|title|diff|oldid|label|diffonly=yes}}

The title parameter is the title of the relevant page (optional in most cases). The diff and oldid parameters are as previously discussed. The label parameter is to specify an optional display label for the link (without one a number will be used). The diffonly=yes parameter is optional, and as discussed earlier, can be added to avoid including a page preview in the diff.

The {{URL to diff}} template

The {{URL to diff}} template provides a means of creating an instance of a {{diff}} template directly from a full diff URL, without having to manually construct one by extracting parameter values.

The syntax is:

{{Subst:URL to diff|url=diffurl|label=mylabel}}

Where diffurl should be replaced with the full URL, and mylabel should be replaced with a display label for the link.

Note that as demonstrated, use of this template needs to be substituted.

As an example, {{Subst:URL to diff|url=https://en.wikipedia.org/w/index.php?oldid=54321&diff=prev|label=my diff link}} will produce a link like this: my diff link

Deleted revisions

A deleted revision is a version of an article that for some reason has been made "invisible" to the general public. This is occasionally done for reasons like significant copyright violations, disruption, or personal attacks on other Wikipedia contributors.

An administrator can see deleted revisions and related diffs, but those diffs can only be shared with other administrators. In order to allow all users to view the diff, the revisions in question need to be visible to them. It is possible for an administrator to restore a deleted revision if warranted.

See Wikipedia:Revision deletion for further details.

Weave diffs

When moving or copying a piece of text within a page or from another page, and also making other edits in the same revision, the diff can still compare moved paragraphs, even if they were moved over 20 paragraphs away. Before August 2018, a diff could be kept clearer (simpler) by first using a separate edit to insert blank lines plus move the text paragraphs, then after saving, in further revisions, add or change text within the moved paragraphs. Only if paragraphs are both split and reworded in the same revision can the specific new words be individually highlighted as different from the prior revision. A split paragraph will typically highlight the 2nd part(s) as if new text on the page. The weave-diff can compare paragraphs word-for-word if moved, but not if split.

A diff shows differences per line, so it synchronizes between revisions by matching the newlines and unchanged lines. Some editors find that having additional line breaks to break up the text improves the diff function. Otherwise, those large, massive globs of text can be difficult to compare after a split. Keep sentences limited in length, such as with four prepositions, and seek shorter paragraphs. Long wp:reftag footnotes (<ref>...</ref>) may be split with internal newlines as well.

Searching diffs to spot a particular change

If you're trying to find the point in a page's history where a particular change was made, and searching the edit summaries does not help, try taking the diff between points roughly 1/3 and 2/3 of the way through the history. From this diff, you can work out in which of the three parts of the history the change occurred. Repeat this process, narrowing the "search space" by a factor of three each time, until the precise edit where the change was made is identified.

You can alternatively use the external WikiBlame tool, which automates this searching process.

Format for displaying a diff

In the case of the Classic skin with quickbar, the diff page does not have the quickbar, to provide more space. Therefore, the diff page is also useful for viewing the page in full-screen width, without changing the preferences. With the Monobook skin the panels on the left are also on the diff page.

On a diff page, sometimes the whole display might be wider than the screen window, often because some website URLs (especially long ones) are not hidden and do not wrap in a diff column. In such cases, you must then use the horizontal scrollbar of the browser to see the whole width of the display. There is no option to wrap the long lines in the diff display.

Comparing different pages

To view a diff between two separate pages (optionally, at specific revisions), use Special:ComparePages (example). [clarification needed]

Using user scripts

You can also tweak the display of your diffs by using various User scripts. See Diffs subsection for more info.

See also