tags:

views:

1415

answers:

8

You're using subversion and you accidentally checkin some code before it's ready. For example, I often: a) checkin some code, then b) edit a little, then c) hit up, enter to repeat the previous command which unfortunately was a checkin.

Is it possible to retract such an accidental checkin from the server with subversion?

A: 

Yes, this is really what Subversion is for.

What you need to do is just replace your copy with previous revision in SVN repository.

There are several options:

  1. Replace with Revision.
  2. Replace with URL
  3. Latest from repository (but in your case, you already have the latest)
  4. Replace with Branch

But I strongly recommend you to do the following prior to replace your local copy:

  1. Do a 'Compare with Repository/ Revision / URL'.
uuɐɯǝʃǝs
That only changes the local copy. I want to retract the checkin from the server.
marcog
If you really don't want to leave any history, you can always delete the whole repository and re-create it again.
uuɐɯǝʃǝs
A: 

I would doubt it. One of the main ideas of a source control is that a repository does not loose any history. You can't delete history. The best you can do is get an older version and overwrite the current one with that. But the history logs will still show your mistake.

(Offtopic: What kind of IDE are you using that does something like that?)

Vilx-
heh, using vim + separate shell for checkin
marcog
Suggestion: use an IDE with integrated SVN support. Way easier. :)
Vilx-
+1  A: 

Using TortoiseSVN, select Show log and locate the revision that you want to revert to. From the context menu, select Revert to this revision. This performs a reverse merge into your working copy, so you will have to commit your working copy to finish the operation.

See also http://stackoverflow.com/questions/747597/how-do-we-keep-track-of-our-working-copys-branch :-)

Jamie Ide
+12  A: 

See the Red Book, specifically the 'Undoing Changes' section, and reverse merging.

Another common use for svn merge is to roll back a change that has already been committed. Suppose you're working away happily on a working copy of /calc/trunk, and you discover that the change made way back in revision 303, which changed integer.c, is completely wrong. It never should have been committed. You can use svn merge to “undo” the change in your working copy, and then commit the local modification to the repository. All you need to do is to specify a reverse difference:

$ svn merge -r 303:302 http://svn.example.com/repos/calc/trunk

To clarify, your initial change will still be in the repository. But you've now retracted it in a later revision. i.e. the repository has captured all your changes (which is really what you want! Unless you've checked in a plaintext password or similar!)

Brian Agnew
This is a feasible solution. Thanks.
marcog
does the same thing but I prefer svn merege -c -303 for undoing changes. Seems to be easier for people to understand.
Jeremy French
Ah. I shall check that out. Thx for the update
Brian Agnew
@JeremyFrench -c worked where the -r didn't not quite sure why, but thanks 1M!
Justin
A: 

you cannot retract the revision, the most you can do is revert back to prior revision and do another checkin.

Nuno Furtado
You can. See svndumpfilter.
Constantin
+2  A: 

You cannot remove the revision - several answers here seem to be totally misunderstanding what you want. But you can change the checkin message to indicate that it it was unintended. Checkins don't cost very much so having the odd extra one is no big deal.

anon
A: 

To comment on this as well: This is a series of commands that I did on a repository to revert it from revision 2 back to revision 1. You'd need to checkin at the end as well though.

Last login: Mon Apr 13 16:01:34 on ttys004
[wlynch@orange ~] cd /tmp
[wlynch@orange /tmp] svnadmin create foo
[wlynch@orange /tmp] svn co file:///tmp/foo foo-repo
Checked out revision 0.
[wlynch@orange /tmp] cd foo-repo/
[wlynch@orange foo-repo] ls
[wlynch@orange foo-repo] touch blah
[wlynch@orange foo-repo] touch repl
[wlynch@orange foo-repo] touch bar
[wlynch@orange foo-repo] svn add *
A         bar
A         blah
A         repl
[wlynch@orange foo-repo] svn ci
Adding         bar
Adding         blah
Adding         repl
Transmitting file data ...
Committed revision 1.
[wlynch@orange foo-repo] echo "hi" > bar
[wlynch@orange foo-repo] echo "oh no" > blah
[wlynch@orange foo-repo] svn ci
Sending        bar
Sending        blah
Transmitting file data ..
Committed revision 2.
[wlynch@orange older-foo] svn diff -r 1:2 file:///tmp/foo
Index: bar
===================================================================
--- bar (revision 1)
+++ bar (revision 2)
@@ -0,0 +1 @@
+hi
Index: blah
===================================================================
--- blah    (revision 1)
+++ blah    (revision 2)
@@ -0,0 +1 @@
+oh no

[wlynch@orange foo-repo] svn diff -r 1:2 file:///tmp/foo | patch -R
patching file bar
patching file blah
sharth
+2  A: 

If what you meant is, how do I cleanly remove the history of an accidental checkin: This is difficult.

svn does not allow you to undo anything since it saves revisions as changesets. However, there are some tools, that let you do almost everything on a dump of a repository. You could :

dump your repo.

use one of these tools (can't remember links, but google will help) to get rid of the checkin.

put it back into the repo.

but this course of action can completely ruin your repo, so never ever try to do this, unless you absolutely know what you are doing and have everything backed up.

EDIT: info from comment (thx man!) and my own googlin:

svn admin tools

AndreasT
I was just about to post this... +1 for beating me to it
rmeador
oh, and the tool you're looking for is "svndumpfilter", IIRC
rmeador