While programming software stored in a Subversion repo, I often modify some files, then notice that I\'d like to do some preparatory change for my main work. E.g. while impl
The branching and patching ideas above are great, but they don't work well for me. I use a visual diff tool, so running git diff
doesn't produce text-based patches. Our build system spins up a new environment each time a branch is created, so creating temporary "stash" branches would get messy.
Instead, I wrote a little shell script that copies a file to a "shelf" directory, adds a timestamp, and reverts the change. It's not as robust as the solutions above, but it also avoids some of the pitfalls that I ran into.
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.
I don't know of an easy way to do that with just svn. Honestly, I'd advise using git-svn
to make a git repo that acts as an svn working copy, and just using git stash
with that. Just replace git pull
with git svn rebase
and git push
with git svn dcommit
and you can actually keep 90% of your git workflow and still be talking to an svn server.
I always keep a second checkout, which I call "trunk_clean". Whenever I need to do a quick, isolated change related to what I am doing, I just commit on that checkout instead.
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).
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.)