How To Create A Patch

Table of contents:

How To Create A Patch
How To Create A Patch

Video: How To Create A Patch

Video: How To Create A Patch
Video: How to Create and Apply Git Patches 2024, May
Anonim

Patches are widely used on UNIX-like systems to propagate small changes made to sets of different files (for example, software source code). They only contain information about the edits that need to be made to the original file to modify it to its current state.

How to create a patch
How to create a patch

Necessary

installed diff utility

Instructions

Step 1

Prepare a source file with information that you will be creating a patch to change. The data in the file can be both text and binary

Step 2

Create a duplicate of the file prepared in the first step. Copy it to another directory with the same name or to the current directory but with a different name

Step 3

Modify the duplicate file created in the previous step. Edit the text as appropriate in a suitable editor, or overwrite the data in the file with the application intended to work with it

Step 4

Review the information on using the diff utility. Start a terminal emulator or switch to the console. Run the command: diff --help to display the online help. Try the commands: man diff or info diff to display the appropriate documentation pages, if installed. Pay special attention to the -a, -c (-C), -e, --normal, and -n (--rsc) options

Step 5

Create a patch. Run the diff command with the options you want, redirecting its output to a file. Specify the original and modified files as parameters following the options. The simplest example of using diff to generate a patch based on data from files located in the current directory might look like this: diff source.txt modified.txt> sample.patc

Step 6

View the generated patch. Use a suitable text editor, or print it to the console with the cat command. For example: cat sample.patchor cat sample.patch | mor

Step 7

Check the correctness of the created change file. Use the patch command. Pass the patch path to it with the -i option. Use the -o option to assign a filename to the result. This will prevent overwriting the original file, the path to which should be specified as the last parameter. For example: patch -i sample.patch -o test.txt source.txt Compare the generated file and the one that was created in the third step. They must be identical. Run the patch command with the --dry-run and --verbose parameters, passing in the penultimate and last arguments to the source and patch file names: patch --dry-run --verbose source.txt sample.patch No changes will be made to the files, but a detailed report on the actions that would have been performed during the actual execution of the command will be displayed. It can also be used to judge the correctness of the created patch.

Recommended: