How to make a patch

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.