how to include a new file into a patch
Solution 1
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
Solution 2
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.
Related videos on Youtube
manuzhang
Software Engineering student at East China Normal University. Know some basics of Haskell and functional language but eager to explore more. Interested in Android developing. Currently enthusiastic about Cassandra and NoSQL DBMS. Want to get my feet wet in web programming.
Updated on September 18, 2022Comments
-
manuzhang over 1 year
I try to make a patch as introduced here.
Say I have two directoriespp1(modified version)
andpp0(clean version)
, I make a patch filepp0.patch
with thediff
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 succeedpatch --dry-run -p1 -i /path-to-pp0.patch
Though I've added
--new-file
to thediff
command, those only inpp1
are not listed in the resultUPDATE:
I've accidentally patched the wrong file sodiff -crb --new-file pp1 pp0 > pp0.patch
or
diff -crNb pp1 pp0 > pp0.patch
will do
-
manuzhang about 12 yearsI don't know whether I've patched it correctly but the new file is not included
-
manuzhang about 12 yearsmy apology, that works
-
manuzhang about 12 yearsthx, wish I could have one in real life and reverted to the past when making a mistake :)