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.)
The working copy will be located in a directory called trunk on your computer relative to the directory you issued the command in. If you wish to have a different name for your working copy you can add that as a parameter to the end of the command. e.g. This will create a working copy called MyProjectSource .
Right click on the selected revision(s), then select Context Menu → Revert changes from this revision. Or if you want to make an earlier revision the new HEAD revision, right click on the selected revision, then select Context Menu → Revert to this revision.
A Subversion working copy is your own private working area, which looks like any other ordinary directory on your system. It contains a COPY of those files which you will have been editing on the website. You can edit these files however you wish, in the usual way.
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.
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) ;)'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With