Although various version control tools are widely used, sometimes you still need to use the original method to submit the patch. It is actually very simple to create the patch.diff
Command, add-u
The parameter generates a diff file in the unified format with the context, which is a patch
. However, the easiest thing to forget is whether to write the version that has not been modified or the version that has been modified first. I can't remember it every time. I want to check man page.
. I just received a patch today and found that all the changes in the patch are the opposite. It is probably because the parameter is reversed.
So I finally decided to write down the correct usage:
diff -u original new > original.patch
I hope I can remember it, even if I cannot remember it, I can easily find it here.
Update 2008-08-02
: The patch method is very simple, as long
patch < original.patch
That's enough, because patch is a program written by Larry Wall that is as smart as Perl!
But sometimes you need to add-p
Parameters, such as patch:
--- foo/bar.c 2008-08-02 08:19:03.000000000 -0400+++ foo_new/bar.c 2008-08-02 08:19:22.000000000 -0400@@ -2,6 +2,6 @@ int main(int argc, char *argv[]) {- printf("hello world/n");+ printf("Hello world!/n"); return 0; }
The patch is generated in the previous directory, so you need to use-p1
Skip a directory:
patch -p1 < ../bar.patch
In this way, there is no problem in daily use!