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

前端 未结 16 1776
轮回少年
轮回少年 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 18:02

    Use:

    svn cp --parents . ^/trash-stash/my-stash
    

    It will create a branch from the current location and current revision, and then it will commit the changes in working copy to that branch without switching to it.

    usage: copy SRC[@REV]... DST

    SRC and DST can each be either a working copy (WC) path or URL:

    WC  -> URL:  immediately commit a copy of WC to URL
    

    Note that changes in working copy won't be automatically reverted (cp is just CoPying changes to a new branch) and you have to revert them manually.

    To restore the changes, you can just merge the changes from newly created branch to your working copy.

    svn merge --ignore-ancestry ^/trash-stash/my-stash -c 
    

    --ignore-ancestry is used in order not to update merge info in working copy.

    Use:

    svn ls -v ^/trash-stash/
    

    to see what you have at stash path. Committed revisions are also printed.

    If you don't need the stash anymore, just run:

    svn rm ^/trash-stash/my-stash
    

    This solution is better than using patch in that if new changes in working copy or on the current branch conflict with the changes in the stash, you can resolve the conflicts using svn means, whereas patch in some cases will just fail or even apply patch incorrectly.

提交回复
热议问题