svn help patch

2007-10-03, Comments

Suppose you want to temporarily revert local changes made to your working copy, then later restore your work in progress. There are a few ways to do this. Perhaps the simplest would be to move, replicate, then revert.

$ mv working_copy working_copy_mine
$ cp -R working_copy_mine working_copy
$ svn revert -R working_copy

Now all your changes to working_copy have been reverted and it contains what you originally checked out (the BASE revision, in Subversion terminology, and note that this revision has been cached locally in the .svn directories, so svn revert has no need to visit the server). When you’re done, tidy up and put your modifications back.

$ rm -rf working_copy
$ mv working_copy_mine working_copy

If it’s a large working copy you can save time, disk space and keystrokes by avoiding the replication. First, save local differences made to your working copy, then revert it.

$ svn diff working_copy > working_copy.patch
$ svn revert -R working_copy

Incidentally, you can fiddle around with working_copy as much as you want now; svn revert will always restore the BASE revision.

When done, patch your changes back in. Note there is no svn patch command; Subversion’s native command for this kind of thing is svn merge which only works on changes actually committed to the repository. Instead, you’ll have to use good old patch.

$ patch -p0 working_copy < working_copy.patch

Take care, though. If you’ve modified your working copy’s structure (svn add|delete|move) or changed its properties (svn propset|propedit|propdel), this technique won’t work.

I’d also suggest that if you regularly find yourself wanting to shuffle tentative changes in this way, you probably ought to be committing them on a private code branch where Subversion can manage them for you.