How to make and apply SVN patch? How to make and apply SVN patch? linux linux

How to make and apply SVN patch?


Use svn patch.

Case 1: using /usr/bin/patch:

svn diff > $TMPDIR/mypatchfile.patchcd myOtherCheckOutpatch -p0 < $TMPDIR/mypatchfile.patch

Applies your changes well if there are no added/deleted files through svn add or svn delete

Case 2: using svn patch:

svn diff > $TMPDIR/mypatchfile.patchcd myOtherCheckOutsvn patch $TMPDIR/mypatchfile.patch

Tracks added and deleted files too.

Note that neither tracks svn moves and renames


By default, patch ignores the directory portion of the target filename; it's just looking for "httpd.conf" in your current working directory. If you want it to use the full path, you have to explicitly ask it to do so with the -p option:

patch -p 0 < httpd.patch

The number after -p is how many levels to remove from the filename path; -p N strips off everything up to and including slash number N. The first slash is number 1, so -p 0 means "don't strip anything".

In general, you might be better off not relying on having the full path in the patch file, though; the patch will be more generally useful if it works even for files in a different directory layout. You can always cd into the directory containing the file before running patch (and use a full path to find the patch file itself, if needed, instead).


If you're using TortoiseSVN there is a easy to use interface to create and apply a patch.

To create:

Right click on folder -> TortoiseSVN -> Create patch

You will be prompted to select an output file

To apply:

Right click on folder -> TortoiseSVN -> Apply patch

You will be prompted with an interface to select the file(s) to apply the patches to, and merge if necassary.