Advertisement
thioshp

How to Patch Files [commands diff and patch]

Feb 6th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1.  
  2. cp gmail-contacts-00001.vcf GmailContacts.vcf ./patches/
  3.  
  4. cd patches/
  5.  
  6. 1. Clearly mark OLD and NEW files:
  7. rename files to *-old and *-new
  8. $ mv gmail-contacts-00001.vcf gmail-contacts-old.vcf && mv GmailContacts.vcf gmail-contacts-new.vcf
  9.  
  10. 2. Compare files:
  11. create the patch file using diff command
  12. $ diff -u gmail-contacts-old.vcf gmail-contacts-new.vcf >gmail-contacts.patch
  13.  
  14. 3. Validate the Patch without Applying (Dry-run Patch File):
  15.  
  16. You can dry run the patch command to see if you are getting any errors, without patching the file using –dry-run option.
  17. $ patch --dry-run < gmail-contacts.patch
  18.  
  19. 3. Update OLD file:
  20. create backup file of gmail-contacts-old.vcf before patching i.e. creates gmail-contacts-old.vcf.orig before applying patch to the older filer
  21. $ patch -b < gmail-contacts.patch
  22.  
  23. You can also use -V to decide the backup filename format as shown below. Now you will have a file name “gmail-contacts-old.vcf.~1~”.
  24. $ patch -b -V numbered > gmail-contacts.patch
  25.  
  26. 4. Reverse a Patch that is Already Applied (Undo a Patch)
  27.  
  28. You can use the -R option to reverse a patch which is applied already:
  29. $ patch -R < gmail-contacts.patch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement