You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.0 KiB
Markdown

# Patching
A patch is a source code that updates other source code. It is formatted as a diff, because it represents what is different between two versions of text. You create a __diff__ with thie `diff` utility, which is then applied to the source code using the `patch` utility.
_NOTE_: Other version control systems like git provide their own methods of creating diffs or patching software.
This is an example where we are creating a patch from the original source code using `diff` and then applying it via `patch`.
## Patching in 6 easy-ish steps
Preserve the original source code
```bash
cp cello.c cello.c.orig
```
Change the source code
Generate a patch using the `diff` utility
```bash
diff -Naur cello.c.orig cello.c
```
Save the patch to a file
```bash
diff -Naur cello.c.orig cello.c > cello-output-first-patch.patch
```
Restore the original file
```bash
cp cello.c.orig cello.c
```
Patch the original with the contents of the new patch file using the `patch` utility
```bash
patch < cello-output-first.patch
```