From charlesreid1

Creating Patches

Creating patches with diff

Creating patches with svn

Creating patches from Subversion is straightforward because it automatically outputs in a format that patch can understand and use.

To create a patch file of a source code tree:

cd /path/to/source
svn diff . > ~/patches/patch.file

For example, if I add a comment to a source code file called

$ cd /path/to/src

$ svn status .
M      CCA/Components/Arches/

$ svn diff .
Index: CCA/Components/Arches/
--- CCA/Components/Arches/	(revision 47166)
+++ CCA/Components/Arches/	(working copy)
@@ -1,5 +1,7 @@
+Added a comment
 The MIT License
 Copyright (c) 1997-2010 Center for the Simulation of Accidental Fires and 

then I can see the change in svn diff. It shows the file that was changed, and the line(s) at which the change(s) happened.

The output of svn diff can be piped to a file, which is then a patch file:

$ cd /path/to/src

$ svn diff . > patch_file

This patch file can then be shared with others, emailed, made public, etc., so that others can use the changes that you've made.

To apply the patch, see below.

Applying Patches

Apply a patch by running:

cd /path/to/source
patch -p0 < patch_file

The -p flag tells patch how many levels of directories to strip from the files listed in the patch file. So, if a patch file contains a file path like:


then using -p1 strips dir1 off, using -p2 strips dir2 off, using -p3 strips dir3 off, etc.

This is usually not necessary if you're creating and applying patches from directories with common structures (this is usually the case with svn).