Thursday, March 26, 2009

Revert commit in Subversion

How to undo a commit (or uncommit) in Subversion.

The svn revert command can not be used as it only reverts local changes, ie. restores all files to the checked out revision.

Instead, here's how to do it. Use the svn merge command. It usually merges revisions from one repository into another. However, it can be used to do the opposite: unmerging.

svn merge -c X SOURCE merges commit X from SOURCE repository to working copy. If X is negative it will be regarded as an inverse merge and the commit removed instead of added.

So, the following command reverts revision 34 in the working copy.

svn merge -c -34 .

Don't forget to commit.

18 comments:

Rick Curtis said...

Thanks!

typecast said...

Great, exactly what I was looking for.

Anonymous said...

Thanks for the info ...

I was thinking using a lot of diff and patch

Anonymous said...

Thanks.

Vahid Pazirandeh said...

Sweetness. Thanks! :-)
This is more elegant than "-r Y:X"

Anonymous said...

This is indeed a fantastic resource. Thank you for making this publicly available.

Anonymous said...

perfect - thanks!

Anonymous said...

Thanks!

SlappyTheFish said...

Brilliant - thank you!

Anonymous said...

Perfect, thanks!

anon said...

from the help:
-c [--change] ARG:
[merge?] the change made by revision ARG (like -r ARG-1:ARG) If ARG is negative this is like -r ARG:ARG-1

So "-c -34" will be an alias to "-r 34:33"

Anonymous said...

Thank you very much

Anonymous said...

Thanks, you've saved me a lot of extra work!

Anonymous said...

Thanks a lot

cool said...

cool .. worked like a charm ..:)

Anonymous said...

*g* thanks :)

Alexei Romanoff said...

Thank you! Your post helps me to solve my problem quickly.

Orti said...

many thanks!