|Version 3 (modified by 7 years ago) (diff),|
Patches are a useful concept for handling local code modifications. They can be handy e.g. for transferring (uncommitted) changes from one branch to another (or from one computer to another).
1) Producing a patch
A patch is a file which contains code modifications in "diff" format. You can easily write all local modifications in an svn working copy to a file by doing:
svn diff > patch.diff
This will produce a file called 'patch.diff' which contains all the changes. If you only want the changes from specific files or directories, you can do:
svn diff someDir/ someFile.f90 > patch.diff
If you want to produce a patch of a certain revision (let's say rev. 1234) in an svn repository, you can do:
svn diff -c1234 > patch.diff
This will include all changes made in that particular revision. If you want a patch of all modifications in a given range of revisions, do:
svn diff -r1234:5678 > patch.diff
This will include the modifications of all revisions after 1234 up to (and including) 5678. The changes of revision 1234 will not be included.
2) Applying a patch
Once you have a patch file, you can apply it e.g. to another svn branch (or even to a directory which is not under version control) via:
patch -p0 < patch.diff
This will apply the changes from the patch file to the current directory.
3) Reverting a revision
A committed revision can be reverted by producing a diff of that revision and applying it reversely ("-R"):
svn diff -c1234 > patch.diff patch -p0 -R < patch.diff