Back to Unix_Utilities

See Also diff

patch

1. Usage

1.1. Single File

1.1.1. Create

diff -u oldFile newFile > mods.diff  # -u tells diff to output unified diff format

1.1.2. Patch

This tells patch to apply the changes to the specified files described in mods.diff. Patches to files in subdirectories require the additional -pnumber option, where number is 1 if the base directory of the source tree is included in the diff, and 0 otherwise.

patch < mods.diff
patch oldFile < mods.patch

1.1.3. Undo

#Patches can be undone, or reversed, with the '-R' option:
patch -R < mods. patch

1.2. Whole Folder

1.2.1. Create

http://www.gnu.org/software/diffutils/manual/html_node/Comparing-Directories.html

diff -ur  old-dir  new-dir  >diff.patch

[root@ec2]/srv/www/moin/patch/198# tree MoinMoin 
MoinMoin
|-- Page.py
`-- search
    `-- results.py

1 directory, 2 files
[root@ec2]/srv/www/moin/patch/198# diff -ur MoinMoin /srv/www/moin/env/lib/python2.7/site-packages/MoinMoin | grep -v '^Only in' > 20140214.patch
[root@ec2]/srv/www/moin/patch/198# cat 20140214.patch 
diff -ur MoinMoin/Page.py /srv/www/moin/env/lib/python2.7/site-packages/MoinMoin/Page.py
--- MoinMoin/Page.py    2015-04-21 07:09:44.003000000 +0000
+++ /srv/www/moin/env/lib/python2.7/site-packages/MoinMoin/Page.py    2015-04-21 07:19:20.138000000 +0000
@@ -716,6 +716,10 @@
         @return: pagename of this page, splitted into space separated words
         """
         request = self.request
+        # 2014-02-14 by liyan CustomPageTitle snap1 begin
+        if self.pi.get("title"):
+            return self.pi["title"]
+        # CustomPageTitle snap1 end
         if not force and not request.user.wikiname_add_spaces:
             return self.page_name
 
@@ -1072,7 +1076,10 @@
                     pass
                 else:
                     request.setPragma(key, val)
-
+            # 2014-02-14 liyan CustomPageTitle snap2 begin 
+            elif verb == "title":
+                pi["title"] = args
+            # CustomPageTitle snap2 end
         pi['acl'] = security.AccessControlList(request.cfg, acl)
         return pi
 
diff -ur MoinMoin/search/results.py /srv/www/moin/env/lib/python2.7/site-packages/MoinMoin/search/results.py
--- MoinMoin/search/results.py  2015-04-21 07:23:17.504000000 +0000
+++ /srv/www/moin/env/lib/python2.7/site-packages/MoinMoin/search/results.py  2015-04-21 07:25:27.752000000 +0000
@@ -626,7 +626,10 @@
             matches = []
 
         # Format
-        pagename = page.page_name
+        # 2014-02-14 liyan CustomPageTitle in search result
+        # pagename = page.page_name
+        pagename = page.page.split_title()  
+        # modify over
         f = self.formatter
         output = []
         start = 0

1.2.2. Patch

This tells patch to apply the changes to the specified files described in mods.diff. Patches to files in subdirectories require the additional -pnumber option, where number is 1 if the base directory of the source tree is included in the diff, and 0 otherwise.

patch < 20140214.patch

1.2.3. Undo

#Patches can be undone, or reversed, with the '-R' option:
patch -R < 20140214.patch

2. Reference

MainWiki: patch_Unix (last edited 2015-04-20 21:33:39 by twotwo)