I know the question has been asked before how often to commit with a DVCS. All answers have one thing in common–as often as possible. But they’re usually something like, after finishing a thought, a user story, getting code that compiles, or passing tests.
I was thinking, given that a DVCS gives you you’re own repository, with very cheap commits, doesn’t it make sense, to commit after every change to a file? After all, this is what happens in NetBeans, and you get a nice free “time machine” without even asking for it. If not every change, then at least every save, or compile.
Does this make sense, or do I have the wrong idea about DVCS. My feeling is that this not the workflow most people have with DVCS.
You should certainly try to avoid comitting code which does not work, and perhaps even does not compile (I think even if you clean up hisory with
git rebase --interactivebefore pushing / publishing code). Otherwise value ofgit bisectto find bugs would get greatly diminished.You can use
git commit+git commit --amend(or e.g.stg refreshif you use StGIT patch management interface1) to snapshot your code without introducing commits with non-working core.The rule of thumb is that commit should do one thing, do it well, and do it completely.
Footnotes
1. Or equivalent for other patch management interfaces, like Guilt for Git, or Mercurial Queues (mq) extension distributed with Mercurial, which was inspiration for Guilt.