Tuesday, August 16, 2011

How to Recover History in Subversion (geek alert)

Click now for JiffNotes

WARNING: The Geek Content of this post is rated R for Really Technical Programming Mumbo Jumbo (don't read unless you're familiar with source control systems and hate dealing with them! This post exists to help Googlers like me with similar problems....)

Seriously, you might want to skip it.

Yesterday I spent about three hours fighting with Subversion. Somehow, it deleted a file from the server, when I was trying to switch to a revision. Due to some things that happened today, I'm thinking it actually occurred when I tried to resolve a conflict. Whatever.

Now, I had another local copy of the file, but I needed the entire history, because I was desperately trying to avoid branching (the default strategy for branching: Desperately Try to Avoid).

"No problem," I thought. I'll just commit this here local version, and it'll hook it back up to the history, and I'll be able to get to it."

WELL THAT DIDN'T HAPPEN. The old history didn't show back up; just one line of history from the commit I'd just done.

WHY did I think that'd work? Because it worked that way in CVS, and no one has told me there's any difference between the two in that regard, just that Subversion is "better" than CVS. So far, notsomuch.

Anyway, to reduce my epic battle to the solution you're really here for, if you Googled, there is no way to rectify this situation through Subclipse in Eclipse. You need to use the command line interface to svn. I used this vanilla version for Windows (just unzip the distribution and plop it on your hard drive...there's no install), but you might (and I might!) want to explore TortoiseSVN.

The magic command is then:
svn copy --revision 9752 http://svn.lottloft.com/svn/app/trunk/myProject/src/com/lottloft/test/Test.java http://svn.lottloft.com/svn/app/trunk/myProject/src/com/lottloft/test/Test.java

(Note: svn.lottloft.com doesn't exist, so don't go looking for things there ;)

This looks REALLY strange, but you're essentially copying a past revision on top of the current one. You need to replace 9752 with the revision before you deleted the file (to do this, Show History for the folder containing the file; you'll be able to tell the last good revision from there).

I found lots of sites that suggest you can do a Reverse Merge to get a deleted file back, but that didn't bring the history forward for me, since I deleted then added the file, wiping history. If you just deleted the file, try the Reverse Merge first.

If you got here through Google, would it kill you to leave a comment telling me if this was useful to you? ;)

Nothing to see here! Move along! Pretty pictures coming tomorrow!


Erin said...

Your previous geeky post didn't make any sense to me. This one, however, I can at least follow. Sounds like a PITA, regardless! Glad you got it figured out.

Susan said...

I don't have to use subversion much these days, but I hate it when I can't locate an old version of a document in docushare - it only seems to want to show me the last 5 versions of a document that I checked in, and sometimes I need to go back to earlier renditions.

Annie said...

We've changed source control systems so many times that I've given up trying to learn all of their intricacies and quirks. I like how determined you are to find solutions to these thorny issues!

Jean in Georgia said...


Old Geek-outs