Just commit more!

Over new years this past year I made dura. It’s like auto-backup for Git. It tries to stay out of the way until you’re in a panic, trying to figure out how to rescue your repository from a thoughtless git reset --hard. It makes background commits, real Git commits that you don’t normally have to see in the log, by committing to a different branch than the one you have checked out. Overall, it’s been a blast. I’ve learned a lot from the contributors, like how to write well-formed Rust as well as a bit about Nix.

One recurring quesion has been, “why don’t you just commit more”?

It’s not a bad question. I clearly went through a lot of effort to build a tool in Rust. I could’ve changed my own behavior. I guess it bugged me how many hours were being wasted on rescuing repositories around the world when the answer is so easy: just commit more.

When I was considering building dura, I figured that I got myself into an unrescuable situation about 1-2 times per year. Situations so dire that even git reflog couldn’t save me. I rationalized that I could spend 4 days building it and it would start saving me time in 5-6 years. That seemed worth it to me.

However, now that I’ve started using it, I find that I need it a lot. Like, really, A LOT!

I’ve never been sure how to pronounce reflog. It seems like it should be “ref-log”, but whenever I need to use it, it feels a lot more like “re-flog”. It’s painful. You can’t really use it without understanding a bit about Git internals, and honestly I wish I didn’t know anything about Git internals. I just want to rescue my code.

Instead of reflog, I just expand the log to all branches, tig --all (tig is great btw). Voilà! A list of changes ordered by timestamp. Dura commits every 5 seconds, at most, so the Git log becomes a timestamp ordered log of every change I made regardless if I left a commit message. It’s more verbose than the log I usually want to see, but I only get it when I put it into verbose mode with the --all option.

I do a lot of code reviews and I frequently find myself doing something like:

  1. Checkout PR branch
  2. Make changes. Poke & prod the code. Run tests, etc.
  3. Abandon the changes
  4. Next PR, go to 1.

A lot of times I’ll wish I didn’t abandon the changes. I used to re-type the changes from memory, but now with dura I look back in the Git log, because now I’m committing a lot!

There’s also been a lot of cases where I’m switching between a lot of branches, resetting, merging, etc. and I simply get lost. I could definitely stare at the branches for a while and figure it out what happened, but Dura is a lot easier.

If I knew how useful Dura would have been, I would’ve made it a lot sooner.

Try it out!

If you’re on Mac, it’s gotten very easy. Running brew install dura will not only install, but also setup a launchctl service to keep it running. I’d love to do something similar for Windows & Linux. If that’s your jam, send a PR!