Thursday, July 31, 2008

Restore the history of a file in subversion

I have a file (some_controller.rb) currently at revision 7744 that was deleted and added in revision 7614.

Deleting and adding a file in the same revision doesn't make a whole lot of sense. I'm pretty sure this was done inadvertently by the developer. In any case, doing so effectively erased the history of the file. Now svn log only shows the changes that have been made since 7614 and svn blame shows the committer of 7614 as the primary editor of the file.

Of course, we always want to accurately place we'd like to restore the history of the file.

This can be achieved by restoring a previous version of the file and then re-applying any updates to it. One side-effect is that any changes made between the delete/add revision (7614 in this case) and the new revision will be put in as one revision. Though, if you wanted to, I suppose you could work around that by re-applying the changes one by one.

Here are the svn steps I took to restore the history of the file:

svn mv some_controller.rb some_controller.rb.tmp

svn ci -m "temporary move, restoring the history of the file"

svn cp https://mysvnrepo.url/trunk/app/controllers/some_controller.rb --revision 7613 https://mysvnrepo.url/trunk/app/controllers/ -m "revive old version of some_controller"

svn up

svn cat some_controller.rb.tmp >some_controller.rb

svn ci -m "put new revisions back into some_controller.rb" some_controller.rb

svn del some_controller.rb.tmp

svn ci -m "remove temporary file"

No comments: