Temporarily put away uncommitted changes in Subversion (a la "git-stash")

Solution 1:

This blog post advises using diff and patch.

  • git stash approximately becomes svn diff > patch_name.patch; svn revert -R .
  • git stash apply becomes patch -p0 < patch_name.patch

Note that this doesn't stash metadata changes or (I think) directory creates/deletes. (Yes, svn tracks those separately from directory contents, unlike git.)

Solution 2:

You can store your current changes with svn diff into a patch file, then revert your working copy:

svn diff > stash.patch
svn revert -R .

After you’ve implemented your preparatory feature, you can then apply your patch with the patch utility:

patch < stash.patch

As others have noted this will not work with svn:properties and tree operations (add, remove, rename files and directories).

Binary files could also give problems, I don’t know how patch (or TortoiseSVN in this case handles them).

Solution 3:

When I've got uncommitted changes from one task in my working copy and I need to switch to another task, I do one of two things:

  1. Check out a new working copy for the second task.

    or

  2. Start a branch:

    workingcopy$ svn copy CURRENT_URL_OF_WORKING_COPY SOME_BRANCH
    workingcopy$ svn switch SOME_BRANCH
    workingcopy$ svn commit -m "work in progress"
    workingcoyp$ svn switch WHATEVER_I_WAS_WORKING_ON_BEFORE
    

I have some scripts that help to automate this.

Solution 4:

The easiest way would be to use a temporary branch, like this:

$ svn copy ^/trunk ^/branches/tempbranch
$ svn switch ^/branches/tempbranch
$ svn commit -m "Stashed"
$ svn switch ^/trunk
$ ... hack away in trunk ...
$ svn commit -m "..."
$ svn merge ^/branches/tempbranch .
$ svn rm ^/branches/tempbranch
$ ... continue hacking

This could (and probably should) be put in a script if done on a more regular basis.