Smaller commits help retain my flow state, therefore improving my productivity.
To have smaller commits, you have to be able to slice your task into nano-slices. I have found adopting Angular's commit format to be helpful in the slicing activity.
The part of the commit format that helps me slice my work is the definition of commit types.
You don't have to remember all of the commit types to start with. In day-to-day development, I'd only use four of them: feat, fix, test, and refactor commit types.
Before I start my work, I tend to have these commit types in my head.
What is it that I'm doing now? Is it a `feat` or `fix`? Is it a `test`? Is it a `refactor`? Then I'll start coding, attempt to consciously stop when I'm done, and then commit.
I try to timebox each of my commits. If I can't a single commit to my 25 minutes pomodoro timer, I might have not analysed the task well beforehand.
The types are short and self-evident, therefore they're not too intrusive to your team.
Once you adopt this, your commit history patterns might look like the following:
1. feat/fix > refactor > (perf)
Following @KentBeck's mantra of "make it work, make it right, make it fast".
Notice that `perf` is a separate commit type. I like performance improvement to be done as a separate effort, which encourages less premature optimisation.
2. refactor > feat/fix > refactor
Following @KentBeck's articulation of "When you want to make a change, first, make the change easy. (Warning, this may be hard.) Then make the easy change".
3. test > feat/fix > refactor
The `test` type is not meant for adding *new* tests, but I break Angular's guidelines here especially when I spent too much time writing the new tests.
To keep your commit to be a working commit, ignore that new test (`it.todo` if using jest).
Note: Even though Angular's commit format is now standardised as conventionalcommits, the commit types that I have found helpful are not part of the standard.
conventionalcommits.org/en/v1.0.0/
Bonus: You can use commitlint + husky to ensure to instil the habit of committing this way.
Make sure you're using this package so that the commat format is enforced. npmjs.com/package/@commitlint/config-conventional