Bugs in software are quite natural in my opinion. Probably every developer had an opportunity to receive a bug report from a client or QA engineer. Some of such bugs are quite trivial and easy to fix, but some of them are real brain crackers. The simple ones often do not require some deep understanding, the solution is easy to introduce. For complex and hard developer needs to dig deep into the code to understand the error nature. In bug fixing, there are two things that need to happen: bug needs to be fixed, obviously, and developer need to prove that this bug will not happen again. But how to make sure both of these are true? Below I will make a list of how I am resolving bugs.

Prove that bug is real

How to prove a bug? It is easy - write a test. Sometimes it will be some simple unit test, sometimes some more complex integration scenario. In most cases, QA engineer will provide detailed information on how to reproduce bug and conditions that need to be met. I always make a commit including such a failing test.

Understand why bug happen

Without understanding the problem introducing a proper fix for complex problems is impossible. Often writing a test will lead to understanding the nature of a problem.

Introduce solution

Introduce solution and describe it in a commit message. Please do not take an easy path and confine on simple Fix message. Probably you won’t be happy seeing Fix in git blame while reading the source code of application you maintain, right?

So my bugfix pull requests include at least two code commits.

Commits

First is marked with the red cross because of failing specs - bug proof. Second is bugfix itself. Following commits are optional refactorings. In my opinion, this is the best approach to fixing bugs in code in my opinion.