Is this a good way to create a patch

diff()patch

I would like to create a patch from a specific gcc branch comparing it to the official releases; so when I unpack the tarball from the stable release, I can apply the patch and get the equivalent of what was in that specific branch .

It's the first time I need to create a patch, so it's my very first time doing this and my main concern is to get the options and the parsing right since we are talking about an extremely important piece of software

diff -crB GccStable GccGit > /tmp/fromStabletoBranch.patch

Is this enough and the best way of doing it ?

Best Answer

Yes, this is a good way to create a patch.

In short:

  1. To create patch for single file your command may look like

    diff -Naru file_original file_updated > file.patch

    where

    • -N: treat absent files as empty
    • -a: treat all files as text
    • -r: recursively compare any subdirectories found
    • -u: output NUM (default 3) lines of unified context
  2. To create patch for whole directory:

    diff -crB dir_original dir_updated > dfile.patch

    where

    • -c: output NUM (default 3) lines of copied context
    • -r: recursively compare any subdirectories
    • -B: ignore changes whose lines are all blank

After all to apply this patch one can run

patch -p1 --dry-run < dfile.patch

where switch p instructs patch to strip the path prefix so that files will be identified correctly. In most cases it should be 1.

Remove --dry-run if you are happy from the result printed on the screen.

Related Question