Recipe: Finding difference between files, patching 

To generate difference
======================

$ cat version1.txt
this is the original text 
line2 
line3 
line4 
happy hacking ! 

$ cat version2.txt
this is the original text 
line2 
line4 
happy hacking ! 
GNU is not UNIX

$ diff -u version1.txt version2.txt
--- version1.txt	2010-06-27 10:26:54.384884455 +0530 
+++ version2.txt	2010-06-27 10:27:28.782140889 +0530 
@@ -1,5 +1,5 @@ 
 this is the original text 
 line2 
-line3 
 line4 
 happy hacking ! 
+GNU is not UNIX

To generate patch
==================

$ diff -u version1.txt version2.txt > version.patch
$ cat version.patch
--- version1.txt	2010-07-06 02:26:07.408890676 +0530
+++ version2.txt	2010-07-06 02:26:36.604864949 +0530
@@ -1,5 +1,5 @@
 this is the original text 
 line2 
-line3 
 line4 
 happy hacking ! 
+GNU is not UNIX


To apply patch
==============
$ patch -p1 version1.txt < version.patch
$ cat version1.txt
this is the original text 
line2 
line4 
happy hacking ! 
GNU is not UNIX


Revert changes
==============
$ patch -p1 version1.txt < v.patch 
patching file version1.txt 
Reversed (or previously applied) patch detected!  Assume -R? [n] y

$ cat version1.txt
this is the original text 
line2 
line3 
line4 
happy hacking ! 

Generating diff against directories
====================================

$ diff -Naur directory1 directory2
