Hacker News new | ask | show | jobs
by choletentent 1590 days ago
Let's say you are editing a source code file. You save and you run. Than you tweak, save and run again. But then you would like to go two changes in the past, but you did not make a commit. Very recent changes are not captured by backup systems, no matter how competent they are.

I'd like to have all my files under git, for every save - and frictionless. I know it is a lot to ask.

5 comments

I remember VMS on the VAX did this, it was a major pain in the neck, it was really easy to run out of disk space (although the quota on my account was 1 MB, which was somewhat small even in those days). But consider if this is really what you want. Every habitual save is another version. Every recompile duplicates all the intermediate object files. If you are using Unix and you have /tmp mounted on a versioned file system, every piped command like less or sort will create a new file. If your system uses pagefiles instead of a swap partition (e.g. macOS, Windows), that's going to be really unpleasant.

I've been developing for many years and I can't remember the last time I ran into this problem, so you can try my approach. When I'm debugging something and unsure of my solution, I comment out the original code and put the potential replacement below. If that doesn't work, do the same. I'll sometimes have three or four potential versions. Also, I generally commit every time a task is finished. During development the tasks might be pretty granular ("implemented underlines, strikethroughs, and custom fg/bg colors for text"), but each bug fix gets its own commit ("bug-2309: text was offset incorrectly on Win32"). Between these two, I rarely run into the problem.

Look up "git wip", configure your editor to use it and it keeps an unintrusive 'second branch' in the background.

https://atom.io/packages/git-wip

"git-wip is a script that will manage Work In Progress (or WIP) branches. WIP branches are mostly throw away but identify points of development between commits. The intent is to tie this script into your editor so that each time you save your file, the git-wip script captures that state in git."

> Very recent changes are not captured by backup systems, no matter how competent they are.

Depends, there's backup software for Windows that will watch for file changes and backup immediately. Usually enterprise targetted. You could certainly do that on other OSes, possibly with less nice apis; a half measure would be taking filesystem snapshots continuously or once a minute or ???.

There's filesystems you can use on cd-r/dvd-r, although that doesn't sound pleasant, that would give you the option to go back to any version.

This sounds a lot like what you're describing: https://github.com/tkellogg/dura
For source code, check out Local History if you’re using JetBrains IDEs. If not, there are similiar plugins for other editors too.