patch Command Generator
Generate patch commands to apply a diff to files
Getting Started with patch
## What is patch?
`patch` applies a diff (produced by `diff -u`) to a set of files. It's the classic tool for distributing and reverting changes to source code.
## How to Use
1. **Provide a patch file** via `-i` (e.g. `-i fix.patch`). 2. **Strip path components** with `-p` (commonly `-p 1`) so the paths inside the diff match your tree. 3. **Set Options** (optional): `-R` to reverse, `-d` to run in a different directory. 4. **Copy & Run**: Copy the generated command into your terminal.
Common Flags
### `-p NUM` Strip leading slashes Diff file paths often look like `a/src/app.c` and `b/src/app.c`. Use `-p 1` to strip the leading `a/` / `b/` prefix so `patch` targets `src/app.c`.
### `-i FILE` Read patch from file Apply a patch stored on disk instead of reading from stdin.
### `-d DIR` Change directory Run `patch` as if you had `cd`'d to `DIR` first — handy when applying a patch from the repo root.
### `-R` Reverse Re-apply the patch in reverse, **undoing** a previously applied change. Equivalent to `git apply -R`.
### Verifying Use `--dry-run` (not exposed in this generator) to test without modifying files:
``` patch -p 1 --dry-run -i fix.patch ```
▶What does the -p 1 mean?
▶How do I undo an applied patch?
If this tool has been helpful to you, consider buying me a coffee.
Buy me a coffee