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 (ha, hard Git reset does not remove unversioned files either!) rm -rf wc && svn co <url> wc
.
Update: I’m not after a simple revert, as that does not delete extra files in the working copy. I really want something that would be the same as deleting the working copy and checking it out again, only without having to download the data again. (Obviously I don’t mind losing all the uncommitted changes.)
This question is related to
svn
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)
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) ;)'
Very quick and simple and does exactly what you want
svn status | awk '{if($2 !~ /(config|\.ini)/ && !system("test -e \"" $2 "\"")) {print $2; system("rm -Rf \"" $2 "\"");}}'
The /(config|.ini)/ is for my own purposes.
And might be a good idea to add --no-ignore to the svn command
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
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
Delete the working copy from the OS and check it out again is simplest, but obviously not a single command.
svn revert . -R
to reset everything.
svn revert path/to/file
for a single file
Source: Stackoverflow.com