Remove files that are not in subversion
One of the great features of version control is that I can easily revert back to a known good state. I can do this in Subversion with the following command:
% svn revert -R .
However, if I have new files that are not in Subversion, this command will not delete them. Here is a fun ruby one liner to remove those files:
svn st | ruby -ne 'File.delete($_[1..-1].strip) if $_.match(/^\?/)'
This command loops over svn status and deletes all files from lines that start with ?.
4 comments
Comments
-
There is no need fo ruby! svn st | grep ^\? | xargs rm will do the trick...
-
Correction...
svn st | grep ^\? | cut -c 2- | xargs rm
-
Unfortunately, your solution will not handle filenames with spaces.
-
I like to use awk instead of cut in these situations, sometimes cut + whitespaces are evil :-P Here you are my line: svn st |grep ^\?| awk '{print $2}'|xargs rm