Thursday, November 19, 2009

Adding multiple items to svn in one shot

If you're using subversion or some other version control for your code (if you're not, then you're really doing something wrong unless you're the only developer on the project and even in that case, there are some really good reasons you should be using some version control, even if it means SourceSafe. Well, I was kidding about SourceSafe. Heck, even Microsoft does not use SourceSafe! Any version control except SourceSafe!) chances are that you have been in a situation where you just added a bunch of files to your project and were now faced with the arduous task of adding the whole goddamned bunch to the repository.

I added about 35 images to my project this morning. I was for a moment, wondering how I could avoid adding each image, one by one to the repository. I did not, for the life of me, want to do:

svn add imageFileName

35 times over.

I wasn't using Eclipse which would have probably done this for me in a breeze. (When is there going to be a Cocoa or a Cocoa Touch plugin for Eclipse, btw???)

Google, as you know is my friend. I googled and found stuff. But beware - the first hit in Google does not give you a method that works. The second does, which I reproduce here for you: Open a terminal and navigate to your folder and type:

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

and katakatakatakat.... all your files will be added to your repository in a jiffy!

What's the big deal about this? Not too big. Anybody with a rudimentary knowledge of shell scripting or the Unix command line could have figured this out. Well, true! But how many people do?

You might ask, if you feel all programmers should know shell scripting, why did I need to Google this? Why could I not do it myself. Good question. Next question.

3 comments:

kartikthum said...

Cool, nice one Kamal! Thanks for sharing :)

Shan Chelliah said...

Good question. Next question.

That line is classic!!!!

Srini said...

I can't imagine coding with out eclipse. This one might help me in future. thanks for sharing