I try to make a patch as introduced here.
Say I have two directories pp1(modified version) and pp0(clean version), I make a patch file pp0.patch with the diff command:

 diff -crB pp0 pp1 > pp0.patch

The problem is if there is a file only in pp1, it won't be included into the patch. How to work around it?

I firstly change into the directory of pp0 and test whether the patch will succeed

  patch --dry-run -p1 -i /path-to-pp0.patch

Though I've added --new-file to the diff command, those only in pp1 are not listed in the result

I've accidentally patched the wrong file so

  diff -crb --new-file pp1 pp0 > pp0.patch


  diff -crNb pp1 pp0 > pp0.patch

will do


You should be able to do this using --new-file switch. Taken from diff man page:

          In directory comparison, if a file is found in only  one  direc-
          tory, treat it as present but empty in the other directory.

Try this:

diff -crB --new-file pp0 pp1 > pp0.patch
  • I don't know whether I've patched it correctly but the new file is not included – manuzhang Apr 25 '12 at 21:56
  • my apology, that works – manuzhang Apr 25 '12 at 23:42

The immediate answer: diff -N, as explained by pootzko. You'll find that a lot of patches out there are created by diff -urN.

What can make your life better: start using a version control tool. If you don't know any, start with one of the three main distributed revision control systems, Bazaar, Git or Mercurial. Check in the clean version, work, check in your work as many times as you like, and ask your version control system for a diff between the clean version and your work.

  • thx, wish I could have one in real life and reverted to the past when making a mistake :) – manuzhang Apr 26 '12 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.