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

SvnTortoisesvnIgnore

Svn Problem Overview


If I have a working copy of a Subversion repository, is there a way to delete all unversioned or ignored files in that working copy with a single command or tool? Essentially, I'm looking for the SVN analogue to git clean.

Either a command line or GUI solution (for TortoiseSVN) would be acceptable.

Svn Solutions


Solution 1 - Svn

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

Solution 2 - Svn

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

Solution 3 - Svn

Using TortoiseSVN:

Solution 4 - Svn

This oneliner might help you:

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

Use with care!

Solution 5 - Svn

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.

Solution 6 - Svn

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

Solution 7 - Svn

With powershell:

(svn status --no-ignore) -match '[?]' -replace '^.\s+' | rm

From command line:

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

Solution 8 - Svn

This oneliner works for me (based on Richard Hansen's answer, which surprisingly didn't work for files containing spaces):

svn status --no-ignore | grep '^[I?]' | cut -c 9- | xargs -d"\n" -I{} rm {}

Solution 9 - Svn

Using TortoiseSVN:

  1. Right-Click on the root of the working copy and select TortoiseSVN -> "check for modifications"
  2. Select "Show ignored files"
  3. Sort by "Text status" column
  4. scroll to the "non-versioned" files, now all grouped together; select them all and right-click -> delete
  5. scroll to the "ignored" files, now all grouped together; select them all and right-click -> delete

Not really a nice and clean solution, but the fastest way I know of (on Windows).

Thanks to pkh for the tip with the ignored files.

Solution 10 - Svn

This is similar to other answers, but actually gets ignored files (note the 'I' in the REs):

 rm -rf `svn status --no-ignore | grep '^[\?I]' | sed 's/^[\?I]//'`

Solution 11 - Svn

Somebody said you can't do it from the Windows command line.

Bull.

for /f "tokens=2 delims= " %I IN ('svn st --no-ignore ^| findstr /R "^[I?]"') DO (DEL /S /F /Q /A:H "%I" & rmdir /S /Q "%I")

Does it in one line and doesn't require a single GNU tool. :)

Solution 12 - Svn

you can't delete them with just SVN command line (not sure about GUI tools though) if you are under linux system this might help:

http://www.guyrutenberg.com/2008/01/18/delete-unversioned-files-under-svn/

The other (brutal) method is to commit changes, delete all from folder and checkout again.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNick MeyerView Question on Stackoverflow
Solution 1 - SvnNeilView Answer on Stackoverflow
Solution 2 - SvnRichard HansenView Answer on Stackoverflow
Solution 3 - SvnStefanView Answer on Stackoverflow
Solution 4 - SvnjkramerView Answer on Stackoverflow
Solution 5 - SvngwilkView Answer on Stackoverflow
Solution 6 - SvnMichael SorensView Answer on Stackoverflow
Solution 7 - SvnYanal-Yves FargiallaView Answer on Stackoverflow
Solution 8 - SvnDennis GolomazovView Answer on Stackoverflow
Solution 9 - SvnThomas LötzerView Answer on Stackoverflow
Solution 10 - SvnpkhView Answer on Stackoverflow
Solution 11 - SvnChokesMcGeeView Answer on Stackoverflow
Solution 12 - SvnJuriyView Answer on Stackoverflow