Posted By

blackthorne on 01/04/11


Tagged

diff patch


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

blackthorne
jachin


Diff and Patch


 / Published in: Bash
 

If you make contributions as a coder or else if you want to apply them in your code you will probably stumble upon '''diff''' and '''patch '''tools. They are frequently used in the Open Source Software specially on the Linux kernel. So, let's say you took some code, made some adjustments/improvements of your own and you want to share it to everyone else. One way is to share all the files you changed which shall be replaced by whoever wants to try your changes. This process requires more data and resources and doesn't make it very clear to everyone who his interested in understanding the differences before submitting your code. Besides if someone else makes some change on one or more of these files, sharing the complete files would replace your changes even if they were done in different parts of the code. So, for serious development you should embrace this option and try the diff/patch way.

  1. First generate a patch for others to apply.
  2. For this we use "diff" where the first argument shall be the original file or directory where did you started making the modifications and the second should be a version of the file or directory with the modifications already made.
  3.  
  4. diff -Naur old_file new_file > your_patch_filename.patch
  5.  
  6. or (if applied against directories)
  7.  
  8. diff -Naur old_dir new_dir > your_patch_filename.patch
  9.  
  10. Finally, to apply these patches you use the '''patch '''tool:
  11. patch -p0 < patch_filename.patch
  12.  
  13. Note: This should be applied on the same relative directory where diff was executed. If you don't know which one it is you can check the patch file with any editor and try to figure that out.

Report this snippet  

You need to login to post a comment.