How to roll back commits to an earlier version of a repository in SVN
April 6, 2007 – 8:25 pmI’ve always wanted to know how to do this, and for some reason I always had a hard time finding out how. I needed to rollback a change I had committed to my SVN repository.
The way you rollback to an earlier version of your repository is to do a reverse merge.
Here’s the example off the SVN site. It will do a reverse merge, and roll back the commit you made in version 303.
$ svn merge -c -303 http://svn.example.com/repos/calc/trunk
U integer.c$ svn status
M integer.c$ svn diff
…
# verify that the change is removed
…$ svn commit -m "Undoing change committed in r303."
Sending integer.c
Transmitting file data .
Committed revision 350.
I found the info in the
common use cases example of merging in the nightly SVN docs.



4 Responses to “How to roll back commits to an earlier version of a repository in SVN”
Thanks for the post. I was also looking for this information.
Best wishes.
By Aman on Nov 30, 2007
I don’t get what the ‘-c’ option is, that you’ve put on the svn merge command. When I try this I get:
svn: invalid option character: c
Typing ’svn help merge’ gives:
merge: Apply the differences between two sources to a working copy path.
usage: 1. merge sourceURL1[@N] sourceURL2[@M] [WCPATH]
2. merge sourceWCPATH1@N sourceWCPATH2@M [WCPATH]
3. merge -r N:M SOURCE[@REV] [WCPATH]
1. In the first form, the source URLs are specified at revisions
N and M. These are the two sources to be compared. The revisions
default to HEAD if omitted.
2. In the second form, the URLs corresponding to the source working
copy paths define the sources to be compared. The revisions must
be specified.
3. In the third form, SOURCE can be a URL, or working copy item
in which case the corresponding URL is used. This URL in
revision REV is compared as it existed between revisions N and
M. If REV is not specified, HEAD is assumed.
WCPATH is the working copy path that will receive the changes.
If WCPATH is omitted, a default value of ‘.’ is assumed, unless
the sources have identical basenames that match a file within ‘.’:
in which case, the differences will be applied to that file.
Valid options:
-r [--revision] arg : ARG (some commands also take ARG1:ARG2 range)
A revision argument can be one of:
NUMBER revision number
“{” DATE “}” revision at start of the date
“HEAD” latest in repository
“BASE” base rev of item’s working copy
“COMMITTED” last commit at or before BASE
“PREV” revision just before COMMITTED
-N [--non-recursive] : operate on single directory only
-q [--quiet] : print as little as possible
–force : force operation to run
–dry-run : try operation but make no changes
–diff3-cmd arg : use ARG as merge command
–ignore-ancestry : ignore ancestry when calculating merges
–username arg : specify a username ARG
–password arg : specify a password ARG
–no-auth-cache : do not cache authentication tokens
–non-interactive : do no interactive prompting
–config-dir arg : read user configuration files from directory ARG
By Stewart on Jan 11, 2008
From svn help merge:
The ‘-c M’ option is equivalent to ‘-r N:M’ where N = M-1.
Using ‘-c -M’ does the reverse: ‘-r M:N’ where N = M-1.
svn –version
svn, version 1.4.5 (r25188)
I think you can use -r HEAD:OLD_REVISION_NUMBER if you’re using an old version.
By jon on Jan 14, 2008
Thanks for the info! I couldn’t get to the SVN nightly docs(broken link) but found this:
http://svnbook.red-bean.com/en/1.0/ch04s04.html#svn-ch-4-sect-4.2
By Tom on Apr 15, 2008