What Is A Diff

Jump to: navigation, search


What is a Diff

A .diff is simply is simply a file describing the differences between two files. In the case of drftpd, the same files (our .java source files) from one revision to the next.


Computer users often find occasion to ask how two files differ. Perhaps one file is a newer version of the other file. Or maybe the two files started out as identical copies but were changed by different people.

You can use the diff command to show differences between two files, or each corresponding file in two directories. diff outputs differences between files line by line in any of several formats, selectable by command line options. This set of differences is often called a diff or patch. For files that are identical, diff normally produces no output; for binary (non-text) files, diff normally reports only that they are different.

What Comparison Means

There are several ways to think about the differences between two files. One way to think of the differences is as a series of lines that were deleted from, inserted in, or changed in one file to produce the other file. diff compares two files line by line, finds groups of lines that differ, and reports each group of differing lines. It can report the differing lines in several formats, which have different purposes.


When comparing two files, diff finds sequences of lines common to both files, interspersed with groups of differing lines called hunks. Comparing two identical files yields one sequence of common lines and no hunks, because no lines differ. Comparing two entirely different files yields no common lines and one large hunk that contains all lines of both files. In general, there are many ways to match up lines between two given files. diff tries to minimize the total hunk size by finding large sequences of common lines interspersed with small hunks of differing lines.

Merging with patch

Patch takes comparison output produced by diff and applies the differences to a copy of the original file, producing a patched version. With patch, you can distribute just the changes to a set of files instead of distributing the entire file set; your correspondents can apply patch to update their copy of the files with your changes. patch automatically determines the diff format, skips any leading or trailing headers, and uses the headers to determine which file to patch. This lets your correspondents feed a mail message containing a difference listing directly to patch.

Patch detects and warns about common problems like forward patches. It saves any patches that it could not apply. It can also maintain a patchlevel.h file to ensure that your correspondents apply diffs in the proper order.

Patch accepts a series of diffs in its standard input, usually separated by headers that specify which file to patch. It applies diff hunks (see Hunks) one by one. If a hunk does not exactly match the original file, patch uses heuristics to try to patch the file as well as it can. If no approximate match can be found, patch rejects the hunk and skips to the next hunk. patch normally replaces each file f with its new version, putting reject hunks (if any) into f.rej.

Invoking patch

It's usually best to apply patches to the latest SVN revision.


Type the following line into a console (replace patch_name with the filename of the patch):

patch -p1 < patch_name



Make sure you have TortoiseSVN http://tortoisesvn.tigris.org installed.

Open Windows Explorer
Right-click on the folder with the drftpd source code
open the TortoiseSVN submenu and select 'Apply Patch...'.
Browse to the patch file and select it.
Then, right click on the 'File Patches' window and click on 'Patch All'.

After you're done, close the TortoiseMerge window

Command Line

If all else fails, you can get native windows binaries of the unix diff and patch programs from sourceforge. Thenjust follow the instructions for linux above after you have installed them.


  1. http://www.gnu.org/software/diffutils/manual/html_node/index.html
  2. http://wiki.openttd.com/index.php/SVN
Personal tools