Good version control system usage prevents many disasters, but that doesn't necessarily mean you won't make your own mistakes. Today, I mistakenly included a file in a commit that I didn't want to commit yet. I learned two new tricks while spending a few minutes puzzling the best way to get back to where I was before with that file.
First, make a mistake:
$svn commit -m "..."
Sending dev.cfg
Sending gibe/plugin.py
Transmitting file data ..
Committed revision 114.
svn merge is the tool to use for this:
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 [-c M | -r N:M] SOURCE[@REV] [WCPATH]
Trick #1: use svn merge's 3rd usage pattern with the -c option with the negative of the revision you've committed, and (here comes the trick) use . (the current directory) as the source of the merge:
$svn merge -c -114 .
U gibe/plugin.py
U dev.cfg
With that your working copy is now where the repository was before your commit. Commit that to the repository, and the repository is back where it was before your commit.
Now your working copy is where it was before you made any changes - but you probably want those changes back. Easy enough:
$svn merge -c 114 .
U gibe/plugin.py
U dev.cfg
Now your working copy is back where it was before you did the mistaken commit.
Trick #2: Of course, if your mistake is like mine and you only messed up one file and everything else is as it should be, you can just do this on one file, by using svn merge's 2nd usage pattern:
$svn merge dev.cfg@114 dev.cfg@113
U dev.cfg
Commit that, and your repository is back to normal. Then run:
$svn merge dev.cfg@113 dev.cfg@114
U dev.cfg
Now the file is back where it was before your botch.