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

前端 未结 16 1581
轮回少年
轮回少年 2020-11-28 17:18

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

相关标签:
16条回答
  • 2020-11-28 17:49

    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.

    0 讨论(0)
  • 2020-11-28 17:50

    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.

    0 讨论(0)
  • 2020-11-28 17:56

    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.

    0 讨论(0)
  • 2020-11-28 17:57

    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.

    0 讨论(0)
  • 2020-11-28 17:59

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

    0 讨论(0)
  • 2020-11-28 18:00

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

    0 讨论(0)
提交回复
热议问题