Switching Branches with Unfinished Changes

This article was originally published in the EclipseZone Tips & Tricks section of Javalobby.org

Just today I was coding up a bug fix that I was told was an 'emergency bug fix'. Because of that, I was plowing through the changes necessary in our production bug fix stream. Around 75% through my fix, I was notified that we didn't have approval to deploy an emergency fix, and it was going out in the regular incremental deploy scheduled in a few weeks.

Thankfully, this situation is no big deal in Eclipse. All I had to do is right-click the project that I was working on, and navigate to Team->Switch to Another Branch or Version :

This command is specifically tailored for this situation; when you have uncommitted code and you realize you need to commit it to another branch than the one you are in. All of the 'clean' files will be replaced with the files in the new branch, and the 'dirty' files (any files that you changed) will be retained.