Even though Ben said, that you shouldnt be scared of committing in between fixing the bug, this is only viable as long as you work on a branch or work alone.
If you would do this in a real work environment you would sabotage the work of your teammates, because they would just casually pull the master and the whole company has a non working version of the code base, which is considered lethal.
ALWAYS make sure the master version is as stable as possible.