- Create a new directory (say patchtry) and create to files in it old.txt and new.txt
- Write some content in both the files.
- Now we need to replace the old.txt file with the contents of new.txt. In this case it is extremely easy to copy the contents of new.txt and paste it into old.txt, but if there had been multiple files available for replacement then this wouldn't have been the smart way out. So we use commands to replace old (generally buggy) files with the new ones. This automated replacement is called patching. I learnt two
almost similarways of patching. In both the cases we generate the patch file which contains the difference between the new and the old files. So moving on, - diff old.txt new.txt >patchfile.patch Of course, you can name the patchfile.patch as anything you want and with any extension. (I wanted to name it Imfreaking.awesome but then decided against it). Now we have the file which contains the difference between the new and the old file (known as patch file) and we just need to update our old.txt so we use the following command :
- This patching method is same as above with the difference that it patches the original file itself. There is a slight modification in the commands, as listed below : diff -Naur old.txt new.txt > patchfile.patch
This is the common line.
This is the different line.
My new.txt contains :
This is the common line.
My name is kr0y.
patch old.txt -i patchfile.patch -o old.new.txt
This patching method doesn't patch the original file itself but creates a new file, so make sure that the input file name (old.txt) is not the same as the output file (old.new.txt)
The parameters seem to do something which I am not much aware of right now, so I will go explore about it once I finish this post. Next comes patching of the original file itself without creating another file using patch old.txt < patchfile.patch
P.S. : 1 small note of acknowledgement to bheekling and this site (great post, read it for clarifications/explanations which are missing above) for whatever is written in the above post. Arigato!
1 comment:
Wakari Mashta
Post a Comment