[ACCEPTED]-Add all unversioned files to Subversion using one Linux command-svn

Accepted answer
Score: 82
svn add --force <directory>

Add is already recursive. You just have 1 to force it to traverse versioned subdirectories.

Score: 28

Adds any file with a question mark next 1 to it, while still excluding ignored files:

svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2}' | xargs svn add
svn commit


Score: 23

This will attempt to add all files - but 2 only actually add the ones that are not 1 already in SVN:

svn add --force ./* 
Score: 13

This command will add any un-versioned files 11 listed in svn st command output to subversion.

Note 10 that any filenames containing whitespace 9 in the svn stat output will not be added. Further, odd 8 behavior might occur if any filenames contain 7 '?'s.

svn st | grep ? | tr -s ' ' | cut -d ' ' -f 2 | xargs svn add

or if you are good at awk:

svn st | grep ? | awk '{print $2}' | xargs svn add


Step 1: svn st command

[user@xxx rails]$svn st
?       app/controllers/application.rb
M       app/views/layouts/application.html.erb
?       config/database.yml

Step 2: 6 We grep the un-versioned file with grep command:

[user@xxx rails]$svn st | grep ?
?       app/controllers/application.rb
?       config/database.yml

Step 3: Then 5 remove the squeeze the space between ? and 4 file path by using tr command:

[user@xxx rails]$svn st | grep ? | tr -s ' '
? app/controllers/application.rb
? config/database.yml

Step 4: Then select 3 second column from the output by using cut 2 command:

[user@xxx rails]$svn st | grep ? | tr -s ' ' | cut -d ' ' -f 2

Step 5: Finally, passing these file paths 1 as standard input to svn add command:

[user@xxx rails]$svn st | grep ? | tr -s ' ' | cut -d ' ' -f 2 | xargs svn add
A       app/controllers/application.rb
A       config/database.yml
Score: 10

By default, the svn add command is recursive. Just 7 point it at the top-level directory of your 6 project and it should add any file not already 5 there.

You may want to include the --force option, though 4 keep in mind that this will also add files 3 which are otherwise excluded due to svn:ignore 2 (if you don't use svn:ignore, then you won't 1 have any issues).

Score: 2

None of you guys are fully correct I spend 2 a whole night to fix it and it's running 1 properly in my jenkins:

svn status | grep -v "^.[ \t]*\..*" | grep "^?[ \t]*..*" | awk '{print $2}' | sed 's/\\/\//g' | sed 's/\(.*\)\r/"\1"/g' | xargs svn add --parents
svn commit
  1. status
  2. remove .svn
  3. find ? at the line begining to determine whether it is unversioned (modify it to | grep "^?[ \t]*.*cpp" | will only add cpp)
  4. remove ? (one of the above thread memtion the problem of awk, you may try to use tr or sed instead)
  5. replace splash to linux splash(optional, cygwin need)
  6. enclose line with quote
  7. call xargs(you should add --parent to make sure mid level sub folders are also added if you try to filter cpp or certain file pattern)
Score: 1

The above-mentioned solution with awk '{print $2}' does 5 not unfortunately work if the files contain 4 whitespaces. In such a case, this works 3 fine:

svn st | grep "^?" | sed 's/^?[ \t]*//g' | sed 's/^/"/g' | sed 's/$/"/g' | xargs svn add


sed 's/^?[ \t]*//g'

removes the question mark and 2 empty characters from the beginning and

sed 's/^/"/g' | sed 's/$/"/g'

encloses 1 the filenames with quotes.

Score: 1

An approach using a Perl one-liner to add all files shown 3 with a question mark by "svn st" would 2 be:

svn st | perl -ne 'print "$1\n" if /^\?\s+(.*)/' | xargs svn add

This should also work with space characters 1 in file names.

Score: 0

This version of the above commands takes 9 care of the case where the committed files 8 or the paths to them contain spaces. This 7 command will still fail, though, if the 6 path contains a single quote.

svn st |grep ^?| cut -c9-| awk '{print "\x27"$0"\x27"}' | xargs svn add

I went for 5 the cut -c9- to get rid of the leading spaces 4 and assuming that the svn st command will 3 start filename at the 9th character on all 2 machines. If you are unsure, test this part 1 of the command first.

Score: 0

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

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


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

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

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


More Related questions