I love SVN. It frequently saves my life when I go to update one of my sites and end up crashing the whole thing. Hopefully all the developers out there are using SVN too. If not you really should head over to http://subversion.tigris.org and get dirty with it (I may make a post later about creating/adding repositories, but I think that is pretty well documented). One of the daily issues I face is that Dreamweaver forgets to tell SVN that I added or removed a file. I work in Dreamweaver about 80% of the time when I am coding for a website (the rest the time I use VIM on my Fedora box), and I use their built in FTP to manage files. Lets take todays example where I am checking in a new version of a template for a site that involved deleting and adding tons of images. Heres what my svn st looks like:
Checking this stuff in right now would be a newb mistake. We need to add all the files with a ? and delete all those files with ! from our repository on the next check-in. Maybe I have ADHD or maybe I just like saving time, but either way I found this cool trick online a long time ago to quickly clean this kind of mess up (sorry to the person that shared it, but I forogot who you are). I have two really useful entries in my ~/.bash_profile that helps me to check-in a lot quicker. I used to use svn add –force * to add all the files, but that’s a couple more letters of typing than I would like so I added these aliases:
alias svnadderall="svn st | grep '^?' | cut -b 8- | xargs svn add"
alias svnridallin="svn st | grep '^!' | cut -b 8- | xargs svn rm"
So what on earth do they actually do? Hopefully you understand what svn st does, look at the man svn pages for help if you don’t. We then pipe that output to our buddy grep, which will find every line that starts with a ? and output that. So we then pipe that cut that output’s first 8 characters (the ? and the spaces after it) so that all that is left is the filenames of each of the files that we want to add to the repository, each on their own line. That ouput is thrown over to xargs, which will take each line and pass it as a parameter to the following command. Since we want to add each of those files to the repository, we run svn add on each line and we are done! svnridallin does the same kind of thing, but instead it finds all our ! files (files that we deleted but forgot to tell SVN about) and runs svn rm on them. After quickly typing svnridallin and svnadderall, we can finally run our svn ci -m “thanks aliases!”.
These two little aliases may not save a ton of time, but I found them to be quite useful. I use them all the time now. If you end up using them or if you find another useful SVN trick, drop me a comment and let me know!
Written For Nerds