SVN command to delete all locally missing files

后端 未结 12 2339
说谎
说谎 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:55

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

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

    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/^!//' )
    
    0 讨论(0)
  • 2020-12-12 09:59

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

    0 讨论(0)
  • 2020-12-12 10:04

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

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

    svn delete `svn status | grep ! | awk '{print $2}'`
    0 讨论(0)
提交回复
热议问题