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
svn revert . -R
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:
rm-rf is required, else these directories will not be removedsvn revert . -R && svn status | rm -rf $(awk '/^?/{$1 = ""; print $0}')
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) ;)'
Delete unversioned files and revert any changes:
svn revert D:\tmp\sql -R
svn cleanup D:\tmp\sql --remove-unversioned
Out:
D D:\tmp\sql\update\abc.txt
I was able to list all untracked files reported by svn st in bash by doing:
echo $(svn st | grep -P "^\?" | cut -c 9-)
If you are feeling lucky, you could replace echo with rm to delete untracked files. Or copy the files you want to delete by hand, if you are feeling a less lucky.
(I used @abe-voelker 's answer to revert the remaining files: https://stackoverflow.com/a/6204601/1695680)
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.
Delete everything inside your local copy using:
rm -r your_local_svn_dir_path/*
And the revert everything recursively using the below command.
svn revert -R your_local_svn_dir_path
This is way faster than deleting the entire directory and then taking a fresh checkout, because the files are being restored from you local SVN meta data. It doesn't even need a network connection.
Pure Windows cmd/bat solution:
svn cleanup .
svn revert -R .
For /f "tokens=1,2" %%A in ('svn status --no-ignore') Do (
If [%%A]==[?] ( Call :UniDelete %%B
) Else If [%%A]==[I] Call :UniDelete %%B
)
svn update .
goto :eof
:UniDelete delete file/dir
IF EXIST "%1\*" (
RD /S /Q "%1"
) Else (
If EXIST "%1" DEL /S /F /Q "%1"
)
goto :eof