Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete all unversioned/ignored files/folders in my working copy?

People also ask

How remove file from SVN commit?

To remove a file from a Subversion repository, change to the directory with its working copy and run the following command: svn delete file… Similarly, to remove a directory and all files that are in it, type: svn delete directory…

What is SVN revert?

Reverts any local changes to a file or directory and resolves any conflicted states. svn revert will not only revert the contents of an item in your working copy, but also any property changes.


svn status --no-ignore | grep '^[I?]' | cut -c 9- | while IFS= read -r f; do rm -rf "$f"; done

This has the following features:

  • Both ignored and untracked files are deleted
  • It works even if a file name contains whitespace (except for newline, but there's not much that can be done about that other than use the --xml option and parse the resulting xml output)
  • It works even if svn status prints other status characters before the file name (which it shouldn't because the files are not tracked, but just in case...)
  • It should work on any POSIX-compliant system

I use a shell script named svnclean that contains the following:

#!/bin/sh

# make sure this script exits with a non-zero return value if the
# current directory is not in a svn working directory
svn info >/dev/null || exit 1

svn status --no-ignore | grep '^[I?]' | cut -c 9- |
# setting IFS to the empty string ensures that any leading or
# trailing whitespace is not trimmed from the filename
while IFS= read -r f; do
    # tell the user which file is being deleted.  use printf
    # instead of echo because different implementations of echo do
    # different things if the arguments begin with hyphens or
    # contain backslashes; the behavior of printf is consistent
    printf '%s\n' "Deleting ${f}..."
    # if rm -rf can't delete the file, something is wrong so bail
    rm -rf "${f}" || exit 1
done

I know this is old but in case anyone else stumbles upon it, newer versions (1.9 or later) of svn support --remove-unversioned, e.g. svn cleanup . --remove-unversioned.

https://subversion.apache.org/docs/release-notes/1.9.html#svn-cleanup-options


Using TortoiseSVN:

  • right-click on working copy folder, while holding the shift-key down
  • choose "delete unversioned items"

This oneliner might help you:

$ svn status | grep '^?' | awk '{print $2}' | xargs rm -rf

Use with care!


Modifying Yanal-Yves Fargialla and gimpf's answers using Powershell (but not being allowed to comment on the original post by Stackoverflow):

powershell -Command "&{(svn status --no-ignore) -match '^[\?i]' -replace '^.\s+' | rm -recurse -force}

This adds the carat ("^") to specify the start of line, avoiding matching all files that contain the letter "i". Also add the flags for -recurse and -force to rm to make this command non-interactive and so usable in a script.


Many things in SVN can be done in different ways, as evidenced by the varied command line answers given here. With the advent of version 1.7 there is yet another technique for TortoiseSVN that, in fact, provides a finer grain resolution than Stefan's answer provided, letting you select non-versioned files separately from ignored files. Just select TortoiseSvn >> Clean up... to open this dialog.

TortoiseSVN cleanup options