svn add/remove newly added files

Sometimes we have an update of codebase many files updates also new files to be added and also removed, to overcome this issue you will need to add them or remove them without adding/removing files already exsits in the repo, the following command line script solve this issue.

add files

svn st | grep ^? | sed 's/? //' | xargs svn add

remove files

svn st | grep ^! | sed 's/! //' | xargs svn rm

3 thoughts on “svn add/remove newly added files

  1. Matthew says:

    This doesn’t work for me. What command line are you using? I’ve tried it in ZSH and BASH (on Mac OS X) and both throw errors, although the errors are different.

  2. Matthew says:

    Sorry – I misinterpreted the error messages. This did actually work, but for some reason it gave an error for every single file that it added successfully. I’m not really sure why, but for every successful file, it also said it couldn’t find an error with the same directory path, without a file name, and with a question mark at the end where the file name should have been.

    I had hopes that this command might handle file names with spaces, but that seems to not be the case either. The one I’ve been using that works for everything except file names with spaces is:

    svn add `svn status .|grep “^?”|awk ‘{print $2}’x`

    Those back-ticks are shorthand for executing the contents as an embedded command, so the status command is run first, then passed through grep, and then through awk to output the file path as an argument for the add command.

  3. Thibault says:

    For People on windows who wants to avoid using any tool except the standart MS-Dos commands to remove unversioned files :

    FOR /F “tokens=1* delims= ” %G IN (‘svn st ^| findstr “^?”‘) DO rd /s /q “%H”
    FOR /F “tokens=1* delims= ” %G IN (‘svn st ^| findstr “^?”‘) DO del /s /f /q “%H”

    – ‘svn st’ will display the status of each files and folder in the working copy
    – ‘findstr’ will look for each line starting with ‘?’, which mean the file/folder is unversioned
    – ‘FOR’ will use as delimiters and take the tokens after the 1st one (the 1st one is %G, the rest is %H) This way we are exctracting the file/folder from the svn st command output.
    – ‘rd’ will delete folders, ‘del’ will delete files.

Leave a Reply

Your email address will not be published. Required fields are marked *