SVN command to delete all locally missing files

后端 未结 12 2338
说谎
说谎 2020-12-12 09:13

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, i

相关标签:
12条回答
  • 2020-12-12 09:37
    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
    0 讨论(0)
  • 2020-12-12 09:37

    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
    
    0 讨论(0)
  • 2020-12-12 09:40

    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
    
    0 讨论(0)
  • 2020-12-12 09:42

    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
    
    0 讨论(0)
  • 2020-12-12 09:49

    Improved Version

    So the full command is:

    svn st | grep ^! | sed 's/![[:space:]]*//' |tr '\n' '\0' | xargs -0 svn --force rm
    
    0 讨论(0)
  • 2020-12-12 09:52

    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")
    
    0 讨论(0)
提交回复
热议问题