how to include a new file into a patch

31,112

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.

Share:
31,112

Related videos on Youtube

manuzhang
Author by

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, 2022

Comments

  • manuzhang
    manuzhang over 1 year

    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

  • manuzhang
    manuzhang about 12 years
    I don't know whether I've patched it correctly but the new file is not included
  • manuzhang
    manuzhang about 12 years
    my apology, that works
  • manuzhang
    manuzhang about 12 years
    thx, wish I could have one in real life and reverted to the past when making a mistake :)