You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2025-08-14-commits.md
+18-56Lines changed: 18 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,42 +6,30 @@ date: 2025-08-14 10:00:00 +0800
6
6
7
7
# Commit History Best Practices
8
8
9
-
A commit history is a record of changes that you made to your codebase. If you want to understand why you or someone on your team made a particular change to the codebase, having a well-written history will help you along that journey.
9
+
Have you ever found yourself looking at code you wrote 6 months ago wondering why you did it that way? A well-crafted commit history transforms your repository into a comprehensive story of your codebase, where the purpose of every change is understood. In the rest of this blog post I wish to share best practices to achieve this outcome.
10
10
11
11
## Single Logical Changes
12
12
13
-
Every commit should represent a single change that you want to make to the codebase. You may need to make many changes to achieve your goal, and this is what we colloquially know as merge requests or pull requests; I will refer to it as a collection of commits.
13
+
Every commit should represent a single change that you want to make to the codebase. In order to reach a certain objective many changes may need to be made; this is what many know as merge or pull requests; I will refer to it as a collection of commits.
14
14
15
-
When requesting to merge a collection of commits, each commit should represent a single logical step towards your goal. For example:
15
+
For example, "Adding a tertiary styled button". In order for that to be done, we need to generalize the existing button styles, so that they can be extended and have the color changed. This change would be broken down into two logical steps.
16
16
17
-
In order to build my feature, I need to refactor some code. Your first logical step is the refactor. The second step is building out your feature. Doing this allows you to easily backport your refactor into master while you continue on your feature. If the feature is small, it helps reviewers easily understand what impact they should be looking out for.
17
+
- First refactor the button code,
18
+
- Second implement your new button.
18
19
19
-
## Clear Commit Summaries
20
+
## Clear Commit Subject Lines
20
21
21
-
A commit summary should clearly state how the system changes once this commit is applied. Think of expaining WHAT in less then x amount of characters
22
+
A commit subject line should clearly state how the system changes once this commit is applied. Think of explaining WHAT in less than x amount of characters
22
23
23
-
**Good**: "button stays the same size when text changes"
24
-
**Bad**: "designers complained about the button"
24
+
Using our previous example:
25
25
26
-
This makes it easy to understand when looking at the history what are the exact things that have happened to the codebase, making it easier for you to find what you want.
26
+
> **Good**: "button now has API to specify background color"<br /><br /> **Bad**: "Need to refactor the button code for tertiary style"
27
27
28
-
### Tagging commits
28
+
In the good example it is clear how this commit changed the system, if I wanted to understand why the change was made that's what the commit body is for.
29
29
30
-
By tagging it means using part of your allocated summary to encode information into your commit message. for example:
31
-
-**refactor**: Changes the code but does not change any behaviour, no tests should be affected
32
-
-**fix**: Changes a unintended behaviour
33
-
-**feat**: Adds net new behaviour to the system
34
-
-**cicd**: only updates build and tests pipelines
30
+
## Meaningful commit body
35
31
36
-
This makes it easy to see in the past month what kinds of activities did we perform, it also gives reviewers context what code to expect in a commit.
37
-
38
-
If you decide to tag commits, ensure that you do not use vague or ambiguous tags for example "chore", this does not describe what the goal of a commit was, all it does it encapsulates developer emotion about the task at hand.
39
-
40
-
## Meaningful Descriptions
41
-
42
-
The description of a commit message should encapsulate your thoughts around what you did. For example, you may have added some CSS, but you did it in a rushed manner and feel like it can be improved. This is great context for someone in the future to understand why the code is bad and that there is no special thing they are missing.
43
-
44
-
Some examples of good content for history:
32
+
The body is your opportunity to explain WHY you made the change. Using the previous example "We needed to add this API to support tertiary style buttons" gives great context as to the reason for the change. It is also a great opportunity to explain other thoughts and considerations that went into the decision.
45
33
46
34
- How the code can be improved
47
35
- Any challenges you encountered while writing the code
@@ -51,39 +39,13 @@ Some examples of good content for history:
51
39
52
40
Just as we apply style guides to our codebase, commits should follow a consistent format. As long as the content is meaningful, the format does not really matter. For example:
53
41
42
+
- subject line < 50 chars
43
+
- body < 72 chars (per line)
54
44
45
+
## TLDR
55
46
56
-
- summary < 50 chars
57
-
- description < 72 chars (per line)
58
-
- type of change: Enum(refact, fix, feat, cicd, burn)
59
-
60
-
> <type of change>: <summary>
61
-
<br />
62
-
<br />
63
-
<description>
64
-
65
-
66
-
Here are two examples of recent commits.
67
-
68
-
{% highlight ruby %}
69
-
commit 6ad486c23b634f448feecda54eb976d38c401b80
70
-
Author: billybonks <sebastienstettler@gmail.com>
71
-
Date: Wed Aug 13 16:16:30 2025 +0800
72
-
73
-
feat: add support for input groups
74
-
75
-
the css is kinda yolo and not the best can change :D!
76
-
does not handle the case where you can label both elements because it
77
-
requires a bunch more work. specifically how forms are made
78
-
{% endhighlight %}
79
-
80
-
{% highlight ruby %}
81
-
commit e341fa8b2827994af2c57bdb1e1744c134c9befe
82
-
Author: billybonks <sebastienstettler@gmail.com>
83
-
Date: Wed Aug 13 00:25:27 2025 +0800
47
+
When selecting the changes to the commit to add ask yourself **Does this commit contain more than one change that can be separated?**
84
48
85
-
refactor: extract chart design from chart builder
49
+
While writing the subject line, answer the question **How does the system change when my commit is merged?**
86
50
87
-
we will be deleting all the vega code in favour of the backend aggregation
88
-
but this code is still required
89
-
{% endhighlight %}
51
+
When adding the body, ask yourself **Why did I make this change, how could this change be better, why did I do it this way?**
0 commit comments