Wednesday, September 14, 2011

Gotcha of the Day: Streamlining Subversion and Emacs

I've been pleased enough with Subversion + emacs integration that I really haven't yet felt the pull to investigate git and the like. Dealing with branching and merging has been relatively painless, and the whole single-version-number-for-all-files approach seems to work really well for me, too.

The only gotcha I've had is that it's somewhat inconvenient to run a diff (C-x v =) or grab the most recent version (C-x v ~) of a file from within emacs. Emacs trivially lets me know the current version of a file (say, 204), but because files aren't version individually, the previous version of a given file isn't simply the current-version - 1 (that is: version 203 of the file may not be the last time this file was changed, just the last change in the repository). The work around I usually used was to run a quick subversion log (C-x v l), and to note the previous version number.

I knew there had to be a better way, and after a few minutes of searching I discovered it: Subversion Revision Specifiers.

I'd naively assumed that subversion required a version *number* for diff and other operations to work. Turns out, this is just mostly true, there are a few magic version specifiers you can use instead of numbers. The one that fixed my gotcha is PREV. PREV represents exactly what you'd want it to represent:

The revision immediately before the last revision in which an item changed.

From within emacs, I now know I can answer PREV anytime a version number of being asked for. Want to compare a file and the previous version in the repository? No problem, enter PREV for the older version and the HEAD for the current version.

HEAD is also a handy specifier, as I can use it to trivially get a clean copy of a source file out of the repository. I just run: C-x v ~ and enter HEAD.

No comments:

Post a Comment


Related Posts with Thumbnails