Creating a Patch for a Pair of Files

A patch is a text file that contains the differences between one or more pairs of different files. A number of open source programs, including UNIX diff, Subversion, and CVS, as well as commercial applications, including DeltaWalker, are capable of producing patches. The process of updating a file with the differences from a patch file is known as applying a patch or patching. While patches originated in the programming world and are particularly suitable for updating source files to newer versions, they have been successfully applied to any text files.

Use the following options to control the patch creation process:

Patch Format

  • Edit Script—historically, the first output format suitable for automatically transforming one file into another; today, it is almost obsolete. An edit script represents commands that direct ed, the standard UNIX text editor, to change the first file into the second. It lacks context and does not provide the information necessary to apply the patch in reverse, i.e. to transform the second file into the first using the patch.
  • Normal—shows each block of differences with no surrounding context, which is sometimes the clearest way to see how the lines have changed. Because the Context and Unified formats can produce similar outputs with zero lines of context and because they are otherwise superior, this format is no longer widely used; DeltaWalker provides it mostly for compatibility reasons.
  • Context—in this format different lines are shown in context i.e. together with unchanged lines before and after. This makes the patch file more human readable and allows a patch to be applied to a file even when modifications have been made to it since the patch was created. Its characteristics make it the standard format for distributing updates to source code.
  • Unified—inherits most of the characteristics of the Context format, except that it is typically shorter because it omits redundant context lines and the produced output is more human readable.
# lines of context Use this spin edit control to specify the number of context lines i.e. the lines before and after a difference. This option is available only for the Context and the Unified patch formats. The default value is three, however it can be set to any number, including zero. For a context or a unified patch to be applied reliably, a min number of three is recommended.

Encoding

Use this combo box to set the character encoding of the patch file. Most always the character encodings of the first and the second files will be the same; in rare the case they are different you will most likely need to select the same encoding as the one used by the destination file.
Delimiter Use this combo box to choose the line delimiter of the patch file. As with character encoding, if you need to explicitly select a line delimiter here, it should likely be the same as the delimiter of the destination file.

Creating a patch is an operation meaningful only in the context of two files and their relationship with each other, i.e. in two-way comparison; therefore the command is unavailable in three-way comparison.

Appearance

Create Patch UI

Access

Menu File > Create Patch...
Keyboard Shortcut Alt+F, T

Related topics