|
|
# `git commit -m "do a thing"`[^1]
|
|
|
|
|
|
![xkcd Git Commit](https://imgs.xkcd.com/comics/git_commit.png)
|
|
|
|
|
|
Commit messages are important when working with others and keeping things consistent makes reading them easier.
|
|
|
|
|
|
Writing commit messages is a science by itself. It's important to be very descriptive of what you changed and what was affected. You're telling others what you did, after all. Use the imperative mood to describe your changes. [This article](https://chris.beams.io/posts/git-commit/) is a good read on the topic.
|
|
|
|
|
|
## Using `git-cz`
|
|
|
|
|
|
[`git-cz`](https://github.com/streamich/git-cz) can help you keep your commit messages nicely formatted. Use it instead of `git commit`.
|
|
|
|
|
|
0. Assume you start with the following: `$ git status`
|
|
|
```
|
|
|
On branch feature/new-file
|
|
|
Untracked files:
|
|
|
(use "git add <file>..." to include in what will be committed)
|
|
|
|
|
|
src/new_file
|
|
|
|
|
|
nothing added to commit but untracked files present (use "git add" to track)
|
|
|
```
|
|
|
1. Add your file(s): `$ git add src/new_file`
|
|
|
```
|
|
|
On branch feature/new-file
|
|
|
Changes to be committed:
|
|
|
(use "git reset HEAD <file>..." to unstage)
|
|
|
|
|
|
new file: src/new_file
|
|
|
```
|
|
|
2. Run `git-cz`
|
|
|
>Use `$ npx git-cz` or install it globally using `$ npm i -g git-cz` to be able to use `$ git-cz`.
|
|
|
1. Choose the type of change you made
|
|
|
```
|
|
|
? 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)
|
|
|
```
|
|
|
>Press enter to accept your selection.
|
|
|
2. Type your subject line
|
|
|
```
|
|
|
? Select the type of change that you're committing: 🎸 feat: A new feature
|
|
|
? Write a short, imperative mood description of the change:
|
|
|
[-------------------------------------------------------------] 27 chars left
|
|
|
feat: add new_file for git-cz demo
|
|
|
```
|
|
|
>The subject line has a character limit. Keep it brief.
|
|
|
3. Type your message body
|
|
|
```
|
|
|
? Select the type of change that you're committing: 🎸 feat: A new feature
|
|
|
? Write a short, imperative mood description of the change:
|
|
|
[-------------------------------------------------------------] 55 chars left
|
|
|
feat: add new_file for git-cz demo
|
|
|
? Provide a longer description of the change:
|
|
|
add a new file to show how git-cz works and how to use it
|
|
|
```
|
|
|
>If you can summarise the changes you made in the subject line, you can just leave this empty and press enter without typing anything.
|
|
|
4. If your change changes the API, describe what changed
|
|
|
```
|
|
|
? Select the type of change that you're committing: 🎸 feat: A new feature
|
|
|
? Write a short, imperative mood description of the change:
|
|
|
[-------------------------------------------------------------] 55 chars left
|
|
|
feat: add new_file for git-cz demo
|
|
|
? Provide a longer description of the change:
|
|
|
add a new file to show how git-cz works and how to use it
|
|
|
? List any breaking changes
|
|
|
BREAKING CHANGE: new_file now contains different text
|
|
|
```
|
|
|
>Leave this empty if your change doesn't break the API. This is usually the case.
|
|
|
5. If your change resolves an issue, add its ID
|
|
|
```
|
|
|
? Select the type of change that you're committing: 🎸 feat: A new feature
|
|
|
? Write a short, imperative mood description of the change:
|
|
|
[-------------------------------------------------------------] 55 chars left
|
|
|
feat: add new_file for git-cz demo
|
|
|
? Provide a longer description of the change:
|
|
|
add a new file to show how git-cz works and how to use it
|
|
|
? List any breaking changes
|
|
|
BREAKING CHANGE: new_file now contains different text
|
|
|
? Issues this commit closes, e.g #123: #0
|
|
|
```
|
|
|
>You can add multiple issues by separating them with commas: `#40, #41`. You'll leave this empty in most cases, though, and you don't have to use this feature at all.
|
|
|
|
|
|
### Notes on `git-cz`
|
|
|
|
|
|
You can add a scope by using the `--scope` option: `$ git-cz --scope my-scope`. Scopes describe which component of the code base is affected. If you changed the button component, use `$ git-cz --scope button`
|
|
|
|
|
|
Join multi-word scopes with dashes and use all lowercase. *My Cool Scope* becomes `my-cool-scope`.
|
|
|
|
|
|
Keep all text (subject line, message body and breaking changes) lowercase when using `git-cz`.
|
|
|
|
|
|
And that's it, you're ready to `$ git push`.
|
|
|
|
|
|
### Check what it does
|
|
|
|
|
|
`git-cz` creates a commit for you with the information you entered. You can check the commit log at any time using `$ git log`:
|
|
|
```
|
|
|
commit fd7be5a3b3220725b48662f700ded0189c2adccd (HEAD -> feature/new-file)
|
|
|
Author: Alessandro Pittori <a.pittori@linguala.com>
|
|
|
Date: Tue Jun 23 14:42:45 2020 +0200
|
|
|
|
|
|
feat: 🎸 add new_file for git-cz demo
|
|
|
|
|
|
add a new file to show how git-cz works and how to use it
|
|
|
|
|
|
BREAKING CHANGE: 🧨 new_file now contains different text
|
|
|
|
|
|
✅ Closes: #0
|
|
|
```
|
|
|
|
|
|
## Using `git commit`
|
|
|
|
|
|
You can also still commit regularly, of course.
|
|
|
|
|
|
# Footnotes
|
|
|
[^1]: This page assumes you know how to [navigate the command line](Dev Knowledge/Command Line). |
|
|
\ No newline at end of file |