Remove files that are not in subversion

written by paul on January 22nd, 2008 @ 09:11 PM

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

Comments

  • Eduardo Ito on 23 Jan 13:41

    There is no need fo ruby! svn st | grep ^\? | xargs rm will do the trick...
  • Eduardo Ito on 23 Jan 13:44

    Correction...

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

  • Paul Gross on 23 Jan 20:19

    Unfortunately, your solution will not handle filenames with spaces.
  • paco on 20 Feb 02:40

    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

Post a comment

Options:

Size

Colors