Jan 232008
 

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

  6 Responses to “Remove files that are not in subversion”

  1. There is no need fo ruby!

    svn st | grep ^\? | xargs rm

    will do the trick…

  2. Correction…

    svn st | grep ^\? | cut -c 2- | xargs rm

  3. Unfortunately, your solution will not handle filenames with spaces.

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

  5. svn st –no-ignore |grep -e ^\? -e ^I | awk ‘{print $2}’| xargs -r rm -r

    Takes care of ignored files, removes directories, and doesn’t call rm when there is no need to (so this one-liner always returns 0).

  6. a simpler method:

    svn sw –force http://...

Sorry, the comment form is closed at this time.