Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

versioning

svn

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 implementing new functionality, I notice some refactoring which might help me.

In order not to mix two unrelated changes, in these cases I'd like to "stow away" my changes, i.e. revert to the repository version, do some other changes, commit these, then "fetch back" my changes.

git-stash allows to do just that. Is there some way to do this with Subversion, either directly or with some plugin or script. Eclipse plugins would also be fine.

like image 489
sleske Avatar asked Oct 12 '09 12:10

sleske


People also ask

Does git stash save uncommitted changes?

The stash command takes the uncommitted changes in your working directory, both the updated tracked files and staged changes, and saves them. However, the changes aren't finished, and you need to switch to a different branch to quickly fix a bug before continuing on with the current feature.

How do I stash uncommitted files?

In order to stash untracked files, add the “–include-untracked” option to your “git stash” initial command. Alternatively, you can simply use the “-u” which is equivalent to the untracked longer version.

How do I revert local changes in SVN?

Right-click a file in the Current Folder browser and select Source Control > Revert using SVN. In the Revert Files dialog box, choose a revision to revert to. Select a revision to view information about the change such as the author, date, and log message. Click Revert.


2 Answers

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.)

like image 114
Walter Mundt Avatar answered Sep 21 '22 21:09

Walter Mundt


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).

like image 25
knittl Avatar answered Sep 22 '22 21:09

knittl