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
2 Answers 2
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
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– manuzhang2012年04月26日 05:56:56 +00:00Commented Apr 26, 2012 at 5:56