In this post, I will show you how to use semantic commits to use in your personal projects.
Table of contents
Open Table of contents
Semantic Commit Messages
See how a minor change to your commit message style can make you a better programmer.
Format: <type>(<scope>): <subject>
<scope>
is optional
Note: The
<scope>
can be anything specifying place of the commit change. For examplefeat(parser): add ability to parse arrays
.
Example
feat: add function to handle form
^--^ ^------------^
| |
| +-> Summary in present tense.
|
+-------> Type: test, feat, fix, chore, docs, refactor, style, ci and perf.
More Examples:
test
: (adding missing tests)feat
: (a new feature)fix
: (a bug fix)chore
: (build process or auxiliary tool changes)refactor
: (a code change that neither fixes a bug or adds a feature)style
: (markup, white-space, formatting, missing semi-colons …)ci
: (CI related changes)perf
: (a code change that improves performance)
Using git-cz
To use git-cz, you need to install it globally:
npm i -g git-cz
Then, you can use it in your project:
git add .
# flag --disable-emoji is optional and will disable emojis in commit message
git-cz --disable-emoji
You will see the following prompt after running git-cz, you can navigate through the options using the arrow keys and select the type of change you’re committing:
Note: Your prompt may be a little different from the one below and may display emojis if you don’t use the
--disable-emoji
flag.
➜ git cz --disable-emoji
? Select the type of change that you're committing: (Use arrow keys or type to search)
> test: Adding missing tests
feat: A new feature
fix: A bug fix
chore: Build process or auxiliary tool changes
docs: Documentation only changes
refactor: A code change that neither fixes a bug or adds a feature
style: Markup, white-space, formatting, missing semi-colons...
(Move up and down to reveal more choices)
References:
Or you can use git-cz in interactive mode:
git add .
git-cz --non-interactive --type=feat --subject="add function to handle form"
Conclusion
In this post, I showed you how to use semantic commits to use in your personal projects and how to use git-cz to make it easier.