Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVN command to delete all locally missing files

Tags:

file-io

svn

People also ask

How do I delete everything from svn?

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…


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:

  • Examining fields (columns) with awk
  • Using xargs to run shell commands with arguments

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


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

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/^!//' )

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

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)