Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Subversion command to reset the working copy?

Tags:

svn

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.)

like image 429
zoul Avatar asked Jun 01 '11 16:06

zoul


People also ask

How do I find my svn working copy?

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 .

How do I revert changes in svn?

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.

What is Subversion working copy?

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.


2 Answers

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.

like image 187
vcsjones Avatar answered Oct 15 '22 12:10

vcsjones


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) ;)' 
like image 40
niklauzg Avatar answered Oct 15 '22 13:10

niklauzg