« Home | We are now debt free... » | Screen Utility (and my .screenrc) » | Back to Zero. » | Spammers are forging e-mail to appear from this do... » | How to recursively delete files and directories (*... » | My Financial Goal for 2009: 100% Debt Free (foreve... » | Apple and Stanford to offer free iPhone developmen... » | 16,906 miles, 4 cities, and 2 more passport stamps... » | Using screen utility to connect to serial devices » | Fix: Running screen under Mac OS X clobbers path »

[subversion] Using patches to manage temporary coding changes

You are deep into making a fix in the code.  You haven't checked in your code for a while when your client says, "I need a quick fix... now."  If you check in the incomplete code it would cause some breakage.  What do you do?  Checkout the project again into a fresh directory?  Create a branch for your code?  ... None of the above.

Git has a phenomenal feature that allows you to "stash" your current changes and recover them later.  It takes your uncommitted changes and saves the, and reverts the code back to the previous state.  This is extremely helpful when someone interrupts you in the middle of code changes, but you don't want to commit your work to the repository yet.  You can generate a patch, saving your temporary work, and revert/checkout the fresh code from the repository.

You can replicate this functionality with subversion by generating and applying a patch files.

Creating a patch is painless.  All you need to do is use the 'svn diff' command.  Just make sure you added any new files to svn before making the patch:

   1: svn diff > mypatch.patch

It's a good thing to note that you can email your client/coworker with the patch and they can try out your fixes.  This is a good way to have fixes verified before checking them in. 

Next, you can revert everything and start over:

   1: svn revert -R

Now you can do any quick and dirty fixes.  When you are done, simply apply the patch to bring your code back to the state where you left off:

   1: patch -p0 < mypatch.patch

Done.

Labels: