Home Tutorials Tools SVN Quickly Add Files

Login

PayPal Donation

Enter Amount:

Banner

Countries

50.9%GERMANY GERMANY
10.8%UNITED STATES UNITED STATES
4.5%AUSTRALIA AUSTRALIA
4.1%AUSTRIA AUSTRIA
2.9%UNITED KINGDOM UNITED KINGDOM

Visitors

Today: 4


English (United Kingdom)Deutsch (Deutschland)
SVN Quickly Add Files Print E-mail
User Rating: / 0
PoorBest 
Written by Joachim Schwarz   

While using Subversion from the command line it can get rather laborious to add a big amount of new files to the repository, especially if those files are distributed over several directories. Using this little trick can save you a lot of work. It enables you to add a huge amount of files with one single command. 

The first idea one might have is to simply use

svn add .

to add the files to the repository. However this will only get you an error message stating that the current directory is already under version control. This seems to leave you only with the possibility to add one file or directory at a time. This blog entry showed me differently.

A simple svn st already gives us a list of all files not in the repository. Hence it is only logical to use its output. However the output also contains all sorts of other files that for example include changes or are mising in the working copy. To filter out those files we use grep:

svn st | grep ^?

With this we instruct grep to output only lines that start with a "?" (The "^" approximates "starts with").

Now we are almost done, but the "?" at the beginning of the lines is still in the way. With a call to cut which only outputs a selected part of the line we can get rid of it:

svn st | grep ^? | cut -b7-

The argument "-b7-" means that all bytes ("-b") in in the supplied list ("7-" = "from byte 7 to the end") will be output. This removes all status info about the files. Now the only thing left is to pass everything to Subversion. We get the final version:

svn st | grep ^? | cut -b7- | xargs -r svn add

The parameter "-r" makes the command easier to use in scripts by telling xargs to never execute the supplied command in case there is no input present.

If you want to remove files you deleted in the working copy also in the repository then you can use a slightly modified form of this:

svn st | grep ^! | cut -b7- | xargs -r svn delete

 

 

 
Copyright © 2010 better-tutorials.com. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.