Wednesday, February 01, 2012

Reverting or rolling back accidental commits in SVN

When using SVN it's sometimes the case that you'll type:
svn commit
Only to realise that you've just accidentally committed the wrong changes, or even some files you didn't want in the subversion repository.

Obviously the svn revert command won't help as that's for reverting local changes. If you want to undo and roll back your changes from r12345 then the magic SVN runes are:
svn merge -c -12345 .

Then you can review and then commit those changes (with a suitable commit log message about rolling back or undoing the revision).

The option -c -<#> is equivalent to -m <#>:<#-1>. Notice that there is a dash before the number, without it you would get -m <#-1>:<#>. The lone dot just tells SVN to work on the repository in the current directory.

Further details about the merge command options can be found here.

Creative Commons License
The words and photos on this webpage which are created by Toby Gray are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.0 England & Wales License.