How to Undo/Reverse a Patch
You can undo or reverse a patch that you’ve already applied using the -R option use the below command.
Command :
patch -R < patch_file
For example, let’s say you applied hello.patch to hello.c:
patch < hello.patch
patching file hello.c
To reverse the changes made by hello.patch use the below command.
Command :
patch -R < hello.patch
Output :
This will undo the patch, restoring hello.c to its original state before hello.patch was applied.
You can check the file size to confirm the undo worked properly. The file size of hello.c should go back to its original size before patching. So in summary, the -R option allows you to cleanly reverse or undo a previously applied patch.
How to Run Patch Command in Linux?
Sometimes, you install software by compiling it from source code instead of using package managers like yum or apt-get. When a security fix is available for such software, you can’t just upgrade it like you normally would. Instead, you must download the security patch, apply it to the source code, and then recompile the software.
This article explains how to create and apply the diff and patch commands. A patch file contains the differences between two versions of the same file or source code. It is made using the diff command and applied using the patch command.
Run Patch Command in Linux
- Syntax of running patch command in Linux
- Application of the Patch File
- Options and descriptions for patch command
- Create a Patch File using diff
- Apply Patch File using Patch Command
- Create a Patch From a Source Tree
- Apply Patch File to a Source Code Tree
- Take a Backup before Applying the Patch using -b
- Validate the Patch without Applying (Dry-run Patch File)
- How to Undo/Reverse a Patch