SVN command to delete all locally missing files

SvnFile Io

Svn Problem Overview


In SVN is there a command I can use to delete all locally missing files in a directory?

Or failing that, some way of listing only those files that are missing (or, in the more general case, have status A, D, ?, etc.)

Svn Solutions


Solution 1 - Svn

If you're using Mac (Darwin) or Linux you can pipe the outputs of the following commands to svn rm for all missing files. You can set the current working directory to the appropriate directory or subdirectory before running these - dependent on whether you want to run this your entire working copy, or only a subset.

  1. Run an svn status
  2. Search for lines that begin with "!" (missing)
  3. Print the "--force" (svn argument) and the second column (the file name) of the output from #2
  4. Run svn rm using the output of #3 as arguments

So the full command is:

svn st | grep ^! | awk '{print " --force "$2}' | xargs svn rm

References:

Solution 2 - Svn

If you are using TortoiseSVN, just do a Check for Modifications, sort by the Status column, select all the entries marked missing, right-click to open the context menu, and select Delete. Finally, commit to publish the changes to the repository.

If you are on Windows, but prefer the command-line and enjoy dabbling in PowerShell, this one-liner will do the trick:

svn status | ? { $_ -match '^!\s+(.*)' } | % { svn rm $Matches[1] }

That is, filter the output to only those lines showing missing files (denoted by an exclamation at the start of the line), capture the associated file name, and perform an svn rm on that file name.

(Blog post Remove all “missing” files from a SVN working copy does something similar for Unix/Linux.)

Solution 3 - Svn

svn st | grep ! | cut -d! -f2| sed 's/^ *//' | sed 's/^/"/g' | sed 's/$/"/g' | xargs svn rm
  1. svn status
  2. Filter only on missing files
  3. Cut out exclamation point
  4. Filter out trailing whitespaces
  5. Add leading quote
  6. Add trailing quote
  7. svn remove each file

Solution 4 - Svn

I just found this, which does the trick, Remove all “missing” files from a SVN working copy:

svn rm $( svn status | sed -e '/^!/!d' -e 's/^!//' )

Solution 5 - Svn

Thanks to Paul Martin for the Windows version.

Here is a slight modification to the script so Windows files with spaces are taken into account as well. Also the missing.list file will be removed at the end.

I saved the following in svndel.bat in my SVN bin directory (set in my %%PATH environment) so it can be called from any folder at the command prompt.

### svndel.bat
svn status | findstr /R "^!" > missing.list
for /F "tokens=* delims=! " %%A in (missing.list) do (svn delete "%%A")
del missing.list 2>NUL

Solution 6 - Svn

I like the PowerShell option... But here's another option if you're using Windows batch scripts:

svn status | findstr /R "^!" > missing.list
for /F "tokens=2 delims= " %%A in (missing.list) do (svn delete %%A)

Solution 7 - Svn

It is actually possible to completely remove the missing.list from user3689460 and Paul Martin

for /F "tokens=* delims=! " %%A in ('svn status ^| findstr /R "^!"') do (svn delete "%%A")

Solution 8 - Svn

An alternative that works on Linux (bash) for to-be-removed files not containg spaces in path:

svn delete svn delete svn status | grep ! | awk '{print $2}'

Solution 9 - Svn

This shell script, recursively examines (svn status) directories in your project, removing missing files (as the question demands) and adding new files to the repository. It is some sort of "store into the repository the current snapshot of the project".

if [ $# != 1 ]
then
    echo  "usage: doSVNsnapshot.sh DIR"
    exit 0
fi

ROOT=$1

for i in `find ${ROOT} -type d \! -path "*.svn*" `
do

    echo
    echo "--------------------------"
    ( cd $i ; 
    echo $i
    echo "--------------------------"


    svn status | awk '  
            /^[!]/ { system("svn rm " $2) }
            /^[?]/ { system("svn add " $2) }
        '
    )
    echo

done

Solution 10 - Svn

A slight modification of the command line, which works on Mac OS (hopefully even on Linux) and copes with the files the command "svm sr" reports, like "!M" (missing and modified).

It copes with spaces in the files.

It is based on a modification of a previous answer:

svn st | grep ! | sed 's/!M/!/' | cut -d! -f2| sed 's/^ *//' | sed 's/^/"/g' | sed 's/$/"/g' | xargs svn --force rm

Solution 11 - Svn

When dealing with a lot of files, it can happen that the argument input to xargs is getting too long. I went for a more naive implementation which works in that case, too.

This is for Linux:

#! /bin/bash
# 1. get all statii in the working copy
# 2. filter out only missing files
# 3. cut off the status indicator (!) and only return filepaths
MISSING_PATHS=$(svn status $1 | grep -E '^!' | awk '{print $2}')
# iterate over filepaths
for MISSING_PATH in $MISSING_PATHS; do
    echo $MISSING_PATH
    svn rm --force "$MISSING_PATH"
done

Solution 12 - Svn

Improved Version

So the full command is:

svn st | grep ^! | sed 's/![[:space:]]*//' |tr '\n' '\0' | xargs -0 svn --force rm

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
QuestionwheresrhysView Question on Stackoverflow
Solution 1 - SvnPeter AjtaiView Answer on Stackoverflow
Solution 2 - SvnMichael SorensView Answer on Stackoverflow
Solution 3 - SvnivrinView Answer on Stackoverflow
Solution 4 - SvnwheresrhysView Answer on Stackoverflow
Solution 5 - Svnuser3689460View Answer on Stackoverflow
Solution 6 - SvnPaul MartinView Answer on Stackoverflow
Solution 7 - SvnAmfasisView Answer on Stackoverflow
Solution 8 - SvngilyenView Answer on Stackoverflow
Solution 9 - Svncibercitizen1View Answer on Stackoverflow
Solution 10 - SvnStefano BossiView Answer on Stackoverflow
Solution 11 - SvnJonas EberleView Answer on Stackoverflow
Solution 12 - SvnZetaView Answer on Stackoverflow