Is there a Subversion command to reset the working copy?

前端 未结 9 1625
时光说笑
时光说笑 2020-12-23 02:25

Is there a single Subversion command that would “reset” a working copy exactly to the state that’s stored in the repository? Something like git reset --hard or

9条回答
  •  遥遥无期
    2020-12-23 03:03

    To revert tracked files

    svn revert . -R
    

    To clean untracked files

    svn status | rm -rf $(awk '/^?/{$1 = ""; print $0}')
    

    The -rf may/should look scary at first, but once understood it will not be for these reasons:

    1. Only wholly-untracked directories will match the pattern passed to rm
    2. The -rf is required, else these directories will not be removed

    To revert then clean (the OP question)

    svn revert . -R && svn status | rm -rf $(awk '/^?/{$1 = ""; print $0}')
    

    For consistent ease of use

    Add permanent alias to your .bash_aliases

    alias svn.HardReset='read -p "destroy all local changes?[y/N]" && [[ $REPLY =~ ^[yY] ]] && svn revert . -R && rm -rf $(awk -f <(echo "/^?/{print \$2}") <(svn status) ;)'
    

提交回复
热议问题