patch
From NetBSD Wiki
The patch(1) program (invented by Perl author Larry Wall) solves the problem of how to synchronize changes in files. It is the inverse of diff: With diff, you can record the difference between two files, with patch(1), you can change the original file into the new one (or the new one back to the old one, if you apply a "reverse patch")
Example:
$ diff -u a.txt a.new.txt > a.txt.diff $ cat a.txt.diff --- a.txt 2006-06-14 21:40:22.000000000 +0200 +++ b.txt 2006-06-14 21:40:16.000000000 +0200 @@ -1,9 +1,9 @@ line 1 -line 2 +Line 2 line 3 -line 4 +line 4 line 5 +line 6 line 7 line 8 -line 9 line 10 $ patch < a.txt.diff $ diff -s a.txt a.new.txt Files a.txt and a.new.txt are identical
patch(1) can automatically find out the file to patch from the contextual output. If we had used noncontextual output or our file's name has changed, we could use
$ patch renamed-file.txt < a.txt.diff
To get back from the new file to the old, pre-patch file:
$ patch -R a.txt < a.txt.diff
You can also use this to indicate that the diff was accidentally run with swapped arguments. (ie, diff b.txt a.txt was run)
