Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

UPDATE:
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

UPDATE:
I've accidentally patched the wrong file so

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

or

  diff -crNb pp1 pp0 > pp0.patch

will do

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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

 --new-file
          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
share|improve this answer
    
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
add comment

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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