Tuesday, December 29, 2009

Reverting a deleted file in Subversion

Last week I accidently a file from the SVN repo and had to revert the delete. Here's a procedure to

1. Do a svn log on the directory where the file used to exist. That will show the deleted file commit action

bash> svn log --verbose

deleting MSN creative change
r1438 | sudhirv | 2009-12-28 15:13:46 -0800 (Mon, 28 Dec 2009) | 1 line
Changed paths:
D /trunk/lib/ETL/Transform/MSNCreativeTransformByAdId.pm

2. So the above file needs to be reverted. Get the previous version of the file to working copy.

bash> svn copy --revision 1437 \
http://somecompany.com/svn/trunk/lib/ETL/Transform/MSNCreativeTransformByAdId.pm MSNCreativeTransformByAdId.pm

3. Doing a SVN status will now show that there is a file waiting to be added to the rep with previous history. Quoted from the book "The plus sign in the status output indicates that the item isn't merely scheduled for addition, but scheduled for addition “with history”. Subversion remembers where it was copied from. In the future, running svn log on this file will traverse back through the file's resurrection and through all the history it had prior to revision 1438. In other words, this new MSNCreativeTransformByAdId.pm isn't really new; it's a direct descendant of the original, deleted file."

bash> $ svn status
A + MSNCreativeTransformByAdId.pm

4. Use the svn commit to commit the file.

bash> svn commit -m "reverting delete to revision 1437" MSNCreativeTransformByAdId.pm

No comments:

Post a Comment