views:

109

answers:

4

Like many programmers, I'm prone to periodic fits of "inspiration" wherein I will suddenly See The Light and perform major surgery on my code. Typically, this works out well, but there are times when I discover later that — due to lack of sleep/caffeine or simply an imperfect understanding of the problem — I've done something very foolish.

When this happens, the next step is do reverse the damage. Most easily, this means the undo stack in my editor… unless I closed the file at some point. Version control is next, but if I made changes between my most recent commit (I habitually don't commit code which breaks the build) and the moment of inspiration, they are lost. It wasn't in the repository, so the code never existed.

I'd like set up my work environment in such a way that I needn't worry about this, but I've never come up with a completely satisfactory solution. Ideally:

  1. A new, recoverable version would be created every time I save a file.
  2. Those "auto-saved" versions won't clutter the main repository. (The vast majority of them would be completely useless; I hit Ctrl-S several times a minute.)
  3. The "auto-saved" versions must reside locally so that I can browse through them very quickly. A repository with a 3-second turnaround simply won't do when trying to scan quickly through hundreds of revisions.

Options I've considered:

  • Just commit to the main repository before making a big change, even if the code may be broken. Cons: when "inspired", I generally don't have the presence of mind for this; breaks the build.
  • A locally-hosted Subversion repository with auto-versioning enabled, mounted as a "Web Folder". Cons: doesn't play well with working copies of other repositories; mounting proper WebDAV folders in Windows is painful at best.
  • As with the previous method, but using a branch in the main repository instead and merging to trunk whenever I would normally manually commit. Cons: not all hosted repositories can have auto-versioning enabled; doesn't meet points 2 and 3 above; can't safely reverse-merge from trunk to branch.
  • Switch to a DVCS and "combine" all my little commits when pushing. Cons: I don't know the first thing about DVCSes; sometimes Subversion is the only tool available; I don't know how to meet point 1 above.
  • Store working copy on a versioned file system. Cons: do these exist for Windows? If so, Google has failed to show me the way.

Does anyone know of a tool or combination of tools that will let me get what I want? Or have I set myself up with contradictory requirements? (Which I rather strongly suspect.)

Update: After more closely examining the tools I already use (sigh), it turns out that my text editor has a very nice multi-backup feature which meets my needs almost perfectly. It not only has an option for storing all backups in a "hidden" folder (which can then be added to global ignores for VCSes), but allows browsing and even diffing against backups right in the editor.

Problem solved. Thanks for the advice, folks!

+1  A: 

if you use Windows Vista, 7 or Windows Server 2003 or newer you could use Shadow Copy. Basically the properties window for your files will have a new tab 'previous version' that keeps track of the previous version of the file.

the service should automatically generate the snapshot, but just to be safe you can run the following command right after your moment of "inspiration"

'vssadmin create shadow /for=c:\My Project\'

it has defiantly saved my ass quite a few times.

Shadow Copy

Keivan
This sounds like it might work quite well. It's a shame I'm still using XP. Perhaps I should start looking at Windows 7.
Ben Blank
it RTMs next week! otherwise give the RC a try. its a great OS
Keivan
+1  A: 

Most editors store the last version of your file before the save to a backup file. You could customize that process to append a revision number instead of the normal tilde. You'd then have a copy of the file every time you saved. If that would eat up too much disk space, you could opt for creating diffs for each change and customizing your editor to sequentially apply patches until you get to the revision you want.

Dingo
Hmm… my editor actually has a built-in multi-backup system like this which I simply hadn't considered. Duh, me. It looks like it's a global setting, though, which seems like it might get irritating for non-coding uses. On the other hand, I might find I *like* having backups for everything. I'll definitely have to give this one a test-drive.
Ben Blank
A: 

I think it is time to switch editors. Emacs has a variable version-control, which determines whether Emacs will automatically create multiple backups for a file when saving it, naming them foo.~1~, foo.~2~ etc. Additional variables determine how many backup copies to keep.

Martin v. Löwis
+3  A: 

Distributed Version Control. (mercurial, git, etc...)

The gist of the story is that there are no checkouts, only clones of a repository.

Your commits are visible only to you until you push it back into the main branch.

Want to do radical experimental change? Clone the repository, do tons of commits on your computer. If it works out, push it back; if not, then just rollback or trash the repo.

Sufian
Taking Hg as an example (as it's supported by Google Code, which I use frequently), if I make a bajillion local "auto-commits", can I then roll them into a single changeset when pushing to the main branch? Or will each individual twiddling of a few characters be visible to everyone browsing the repository?
Ben Blank
Yes, your commits (hg commit) will be visible to everyone browsing the repository after you push them back. Repeated saves will not. If you save for the minor characters and commit for each working delta, you should be safe from embarassment. Something tells me that this could probably be circumvented, I've just never had to do it myself.
Sufian