Is there a Subversion command to reset the working copy?
Solution 1:
You can recursively revert like this:
svn revert --recursive .
There is no way (without writing a creative script) to remove things that aren't under source control. I think the closest you could do is to iterate over all of the files, use then grep the result of svn list
, and if the grep fails, then delete it.
EDIT: The solution for the creative script is here: Automatically remove Subversion unversioned files
So you could create a script that combines a revert
with whichever answer in the linked question suits you best.
Solution 2:
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:
- Only wholly-untracked directories will match the pattern passed to
rm
- 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) ;)'