Introduction

When maintaining a branch of commits, it’s always best to keep a clean commit history where possible. Git gives you the tools you need for this, and this guide will help you learn how to use them.

What Is A Clean History?

A clean commit history is one where each commit is a solid piece of work, representing a milestone in your feature or fix. This might be the backend for some part of the feature, or a component of the UI. It doesn’t have to be a large amount of work, just some good chunk that, conceptually, stands alone.

An unclean commit history is often littered with commits like "Fixed a bug in my previous commit" or "Oops, forgot this file" or "rewrite that class again for the 3rd time."

Ideally, you should strive for a series of commits that almost reads as a story of how your feature came together.

A good example of a clean commit history is:

* Added the models and forms for potatoes.
* Added the API for interacting with potatoes, along with unit tests.
* Added the comment dialog for reviewing potatoes.

An example of an unclean commit history is:

* Added the models and forms for potatoes.
* Decided the is_spud field wasn't necessary and removed it.
* Forgot forms.py.
* Added the API for interacting with potatoes, along with unit tests.
* One of the tests failed, fixed it.
* Added the comment dialog for reviewing potatoes.
* Fixed a typo.
* Another typo.