No Gravatar

There are many occasions where I will create a few new files at once when doing some work in some code somewhere that is under Subversion control. It used to be the case that when it was time to add these files to the repo with the old svn add command, I would religiously add each file separately – donkey work indeed. Well, I created a better way to do it with one command and now I’d like to pass it on – I am sure that you may see ways to improve it, so let me know!

The Good Old Way
Firstly we run svn st to see what is what…

 $ svn st
 ? lib/file1
 ? lib/file2
 M lib/someotherfile1
 ? foo/bar/file3
 ? foo/baz
 ? ....more files

So in this case, I would have to add all the files manually – becomes more of a problem the more new files there are…

 $ svn add lib/file1 lib/file2 foo/bar/file3 foo/baz ....more files

An Improvement
Instead we add them using a single command – one that stays the same no matter how many new files there are…

$ for i in $(svn st | grep "?" | awk '{print $2}'); do svn add $i; done;

An explanation of the command above goes as follows – it works as a foreach loop, the subject of the loop (each succesive value of i) being an svn st piped into a grep looking for the literal question mark character; the output of the grep is piped into an awk command which prints the second column of characters – the file’s path and name. Therefore on each iteration of the loop the value of i is given to the svn add command.

I would be interested to see if others have ways of doing the same – drop me a comment.

  • Share/Bookmark

One Comment on “Add Multiple Items into SVN Repo at Once”

You can track this conversation through its atom feed.

  1. David says:

    very handy and it saved me a lot of typing.

    thanks!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>