11.07.2015 Views

Version Control with Subversion - Login

Version Control with Subversion - Login

Version Control with Subversion - Login

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Branching and MergingThat was the hard part—the research. Now that you know what you want to restore, youhave two different choices.One option is to use svn merge to apply revision 808 “in reverse.” (We already discussedhow to undo changes in the section called “Undoing Changes”.) This would have the effectof re-adding real.c as a local modification. The file would be scheduled for addition, andafter a commit, the file would again exist in HEAD.In this particular example, however, this is probably not the best strategy. Reverse-applyingrevision 808 would not only schedule real.c for addition, but the log message indicatesthat it would also undo certain changes to integer.c, which you don't want. Certainly,you could reverse-merge revision 808 and then svn revert the local modifications tointeger.c, but this technique doesn't scale well. What if 90 files were changed in revision808?A second, more targeted strategy is not to use svn merge at all, but rather to use the svncopy command. Simply copy the exact revision and path “coordinate pair” from the repositoryto your working copy:$ svn copy ^/trunk/real.c@807 ./real.c$ svn statusA + real.c$ svn commit -m "Resurrected real.c from revision 807, /calc/trunk/real.c."Addingreal.cTransmitting file data .Committed revision 1390.The plus sign in the status output indicates that the item isn't merely scheduled for addition,but scheduled for addition “<strong>with</strong> history.” <strong>Subversion</strong> remembers where it was copied from.In the future, running svn log on this file will traverse back through the file's resurrectionand through all the history it had prior to revision 807. In other words, this new real.c isn'treally new; it's a direct descendant of the original, deleted file. This is usually considered agood and useful thing. If, however, you wanted to resurrect the file <strong>with</strong>out maintaining ahistorical link to the old file, this technique works just as well:$ svn cat ^/trunk/real.c@807 > ./real.c$ svn add real.cAreal.c$ svn commit -m "Re-created real.c from revision 807."Addingreal.cTransmitting file data .Committed revision 1390.Although our example shows us resurrecting a file, note that these same techniques workjust as well for resurrecting deleted directories. Also note that a resurrection doesn't haveto happen in your working copy—it can happen entirely in the repository:$ svn copy ^/trunk/real.c@807 ^/trunk/ \-m "Resurrect real.c from revision 807."Committed revision 1390.$ svn updateA real.cUpdated to revision 1390.99

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!