Monday, February 11, 2008

How to Rollback a SVN Repository to a Previous Revision

Sometimes you might get confused about what to do if you accidentally commit something to a SVN repository. If you want to rollback the SVN repository to the revision before your last commit, this is what you need to do.

a) Update your local copy of the code base to the latest revision.

b) Merge the previous revision to your current code base.

svn merge -rHEAD:xxxx [svn-repository-url] [path-to-local-copy]
  • HEAD – indicates the revision of the local copy of the code is the latest revision.
  • xxxx – is the revision which want to rollback.
  • [svn-repository-url] - is the project's URL in SVN repository
  • [path-to-local-copy] - is the path to the local copy of the project
Example:
svn merge -rHEAD:1010 https://repo.example.org/project1/trunk /home/sanka/project1/trunk

c) Commit the changes which occurs as a result of above steps.

7 comments:

kaffeeringe.de said...

In my case svn skips all the files and the reversion doesn't work :-(

Jason White said...

I had the same problem. I was attempting to rollback commits incorrectly made to a tag. My working copy was linked to the repository base for this project (we have many projects in a single repository) not to a specific branch, tag or trunk. After creating a new working copy linked directly to the tag in question I was able to rollback as directed in the original post.

Чугайстер said...

Thanks for this good article!
It really helps ;)

Anonymous said...

Thanks ! you save my day !

Blair Zajac said...

One should not use -r HEAD in the command line option if somebody else is doing commits at the same time, you may or may not revert it. Always use a fixed revision number instead.

Anonymous said...

Hi,

You help me a lot, thanks for your advice.

I do it with tortoise SVN client with

Merge / Merge two differents trees / From Head revsion - To specific revision / Merge.

Thanks a lot.

François (Belgium)

Anonymous said...

Thanks!