Sometimes I include many files in different directories in my project. For now I am adding all files one by one to my project before commit. Is there any Linux terminal comm
This will attempt to add all files - but only actually add the ones that are not already in SVN:
svn add --force ./*
This command will add any un-versioned files listed in svn st
command output to subversion.
Note that any filenames containing whitespace in the svn stat output will not be added. Further, odd behavior might occur if any filenames contain '?'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
Explanation:
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: 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 remove the squeeze the space between ?
and file path by using tr command:
[user@xxx rails]$svn st | grep ? | tr -s ' '
? app/controllers/application.rb
? config/database.yml
</pre>
Step 4: Then select second column from the output by using cut command:
[user@xxx rails]$svn st | grep ? | tr -s ' ' | cut -d ' ' -f 2
app/controllers/application.rb
config/database.yml
Step 5: Finally, passing these file paths 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
svn add --force <directory>
Add is already recursive. You just have to force it to traverse versioned subdirectories.
This version of the above commands takes care of the case where the committed files or the paths to them contain spaces. This command will still fail, though, if the path contains a single quote.
svn st |grep ^?| cut -c9-| awk '{print "\x27"$0"\x27"}' | xargs svn add
I went for the cut -c9- to get rid of the leading spaces and assuming that the svn st command will start filename at the 9th character on all machines. If you are unsure, test this part of the command first.
The above-mentioned solution with awk '{print $2}'
does not unfortunately work if the files contain whitespaces. In such a case, this works fine:
svn st | grep "^?" | sed 's/^?[ \t]*//g' | sed 's/^/"/g' | sed 's/$/"/g' | xargs svn add
where
sed 's/^?[ \t]*//g'
removes the question mark and empty characters from the beginning and
sed 's/^/"/g' | sed 's/$/"/g'
encloses the filenames with quotes.