Skip to main content

How to Write Git Conventional Commits (feat, fix and BREAKING CHANGE)

· 17 min read
Jagdish Kumawat
Founder @ Dewiride

Conventional Commits is a simple format for Git commit messages: each one starts with a type such as feat or fix, so people and tools can tell what a commit does from its first line. This guide explains the format, then writes every kind of commit in a small practice repository, with Git's real output.

Syntax​

A conventional commit message has a header, an optional body and optional footers, with a blank line between them. This is its general form, from the Conventional Commits 1.0.0 specification:

Syntax
<type>(<scope>)!: <description>

<body>

<footer-token>: <footer-value>
PartRequiredWhat goes there
<type>YesA word that says what kind of change this is, such as feat or fix. The common types are in the next table.
(<scope>)NoThe part of the project the change touches, in parentheses, such as (parser) or (api).
!NoMarks a breaking change: a change that stops something working for the people who use the project. It goes right before the colon.
: YesA colon and a space. Without the space, the message doesn't follow the format.
<description>YesA short summary of the change.
<body>NoMore detail: what changed and why. It starts one blank line after the header and can have several paragraphs.
<footer-token>: <footer-value>NoExtra information, one blank line after the body, such as Refs: #123. A token uses - instead of spaces (Reviewed-by), and Fixes #123, with a space and #, works too.
BREAKING CHANGE: <what breaks>NoThe footer that marks a breaking change and says what breaks. It must be in capitals, and BREAKING-CHANGE means the same.

The specification defines two types, feat and fix, and allows any others. For the others, it points to the list in @commitlint/config-conventional, which comes from Angular's commit guidelines. The descriptions below are commitlint's, shortened:

TypeWhat it's forExample headerVersion change
featA new featurefeat: add a dark themeMinor (1.4.0 → 1.5.0)
fixA bug fixfix: stop the menu closing on scrollPatch (1.4.0 → 1.4.1)
docsDocumentation only changesdocs: explain the install stepsNone
styleChanges that do not affect the meaning of the code (white-space, formatting, missing semi-colons)style: indent with two spacesNone
refactorA code change that neither fixes a bug nor adds a featurerefactor: split the parser into two filesNone
perfA code change that improves performanceperf: cache the price listNone
testAdding missing tests or correcting existing teststest: cover an empty cartNone
buildChanges that affect the build system or external dependenciesbuild: update the image libraryNone
ciChanges to CI configuration files and scriptsci: run checks on every pull requestNone
choreOther changes that don't modify source or test fileschore: ignore log filesNone
revertReverts a previous commitrevert: let us never again speak of the noodle incidentNone
Any type with ! or a BREAKING CHANGE footerA breaking changefeat!: drop support for Node 6Major (1.4.0 → 2.0.0)

The last column follows the specification, which matches commits to Semantic Versioning: a fix means a patch release, a feat a minor release and a breaking change a major release. The other types don't change the version on their own.

The forms you'll type most often:

  • feat: <description> for a new feature
  • fix(<scope>): <description> for a bug fix in one part of the project
  • <type>!: <description>, often with a BREAKING CHANGE: <what breaks> footer, for a breaking change

Prerequisites​

  • Git. Check it in a terminal:
Terminal
git --version
Output
git version 2.56.1
  • Your name and email set in Git, because every commit records them. Git's First-Time Git Setup page shows the two git config commands.

Every command in this guide works unchanged in bash, zsh and PowerShell.

Step 1: Create a Practice Repository​

The example is a tiny project called greeter: one script that prints a greeting. Each step changes it a little, so every kind of commit has something real to describe.

Open a terminal in the folder where you keep your projects and run:

Terminal
mkdir greeter
cd greeter
git init -b main
Output
Initialized empty Git repository in /Users/you/projects/greeter/.git/

mkdir creates the folder, cd moves into it, and git init -b main turns it into a Git repository with a branch called main. How to Create a Git Repository and Make Your First Commit explains git init in detail.

In any text editor, create a file named greet.sh in the greeter folder, with these two lines:

greet.sh
#!/bin/sh
echo "Helo, World!"

The greeting has a spelling mistake: Helo. Leave it there for now. Step 4 fixes it with a fix commit.

Step 2: Commit a New Feature with feat​

Stage the script and commit it with a feat message:

Terminal
git add greet.sh
git commit -m 'feat: add a script that prints a greeting'
Output
[main (root-commit) e40d909] feat: add a script that prints a greeting
1 file changed, 2 insertions(+)
create mode 100644 greet.sh
  • git add stages the file: it goes into the next commit.
  • git commit -m saves the commit with the message that follows.
  • feat says the commit adds a feature: here, the whole script. Then come a colon, a space and the description.
  • e40d909 is the commit's short ID. Yours will be different.

The description starts with a lowercase verb in the present tense: "add", not "Added" or "adds". The specification doesn't require that, but Angular's guidelines, where the common types come from, ask for "the imperative, present tense", no capital first letter and no full stop at the end. commitlint's default rules also reject a description in sentence case, such as "Add a script", and one that ends with a full stop.

The message is in single quotes. Single quotes work the same way in bash, zsh and PowerShell, and Step 6 shows why they matter.

Step 3: Commit Documentation with docs​

Create a second file, README.md, in the same folder:

README.md
# greeter

A script that prints a greeting. Run it with `sh greet.sh`.

Then commit it as documentation:

Terminal
git add README.md
git commit -m 'docs: explain how to run the script'
Output
[main faad9a8] docs: explain how to run the script
1 file changed, 3 insertions(+)
create mode 100644 README.md

docs is for changes to documentation only. Nothing about how the project works has changed, so a docs commit never changes the version number.

Fix the spelling in greet.sh, so the file reads:

greet.sh
#!/bin/sh
echo "Hello, World!"

This commit gets a body that explains the fix, and a footer that links it to an issue. Each -m adds one paragraph:

Terminal
git add greet.sh
git commit -m 'fix: correct the spelling of Hello' -m 'The greeting said Helo instead of Hello.' -m 'Refs: #1'
Output
[main b221545] fix: correct the spelling of Hello
1 file changed, 1 insertion(+), 1 deletion(-)

Git's own documentation for -m says: "If multiple -m options are given, their values are concatenated as separate paragraphs." That's exactly the layout the format needs: the header, a blank line, the body, a blank line, the footers. git log -1 shows the last commit with its whole message:

Terminal
git log -1
Output
commit b221545252cded070b36abc007ececd01f735002 (HEAD -> main)
Author: Your Name <you@example.com>
Date: Tue Nov 24 06:54:03 2026 +0000

fix: correct the spelling of Hello

The greeting said Helo instead of Hello.

Refs: #1
  • The header is the short summary that every one-line view of the history shows.
  • The body says why the change was needed.
  • Refs: #1 points to issue 1 in your issue tracker. In a real project, use the number of the issue the commit fixes.

If you'd rather write a long message in an editor, run git commit without -m. Git opens your editor, and you type the same paragraphs there, with a blank line between them.

Step 5: Add a Scope​

Add a second line to greet.sh:

greet.sh
#!/bin/sh
echo "Hello, World!"
echo "Have a nice day."

Commit it as a feature, with the scope in parentheses:

Terminal
git add greet.sh
git commit -m 'feat(greet): wish the reader a nice day'
Output
[main e372f43] feat(greet): wish the reader a nice day
1 file changed, 1 insertion(+)

The scope, greet, names the part of the project that changed: here, the greet script. In a bigger project, scopes are names like api, parser or ui. Agree on a short list as a team, so the same part always gets the same scope.

Step 6: Mark a Breaking Change​

A breaking change stops something working for the people who use your project. Renaming the script is one: anyone who runs sh greet.sh has to switch to the new name.

Rename the file with Git:

Terminal
git mv greet.sh hello.sh

git mv renames the file and stages the rename in one go. It prints nothing.

The README still names the old file. Change it to the new name:

README.md
# greeter

A script that prints a greeting. Run it with `sh hello.sh`.

Then commit both changes together, with a ! in the header and a BREAKING CHANGE footer:

Terminal
git add README.md
git commit -m 'refactor(greet)!: rename greet.sh to hello.sh' -m 'The new name matches the greeting the script prints.' -m 'BREAKING CHANGE: greet.sh no longer exists. Run hello.sh instead.'
Output
[main 0167d9d] refactor(greet)!: rename greet.sh to hello.sh
2 files changed, 1 insertion(+), 1 deletion(-)
rename greet.sh => hello.sh (100%)

The three -m options built this message, with every part of the format in it:

A commit message in a macOS-style window: the header refactor(greet)!: rename greet.sh to hello.sh with the type, the scope and the exclamation mark highlighted, a one-line body, and a BREAKING CHANGE footer in red.

Commit message
refactor(greet)!: rename greet.sh to hello.sh

The new name matches the greeting the script prints.

BREAKING CHANGE: greet.sh no longer exists. Run hello.sh instead.
  • refactor is the type: the code changed without a new feature or a bug fix. A breaking change can have any type.
  • ! right before the colon marks the commit as breaking, so the header alone says so.
  • The BREAKING CHANGE: footer says what breaks and what to do instead. Either the ! or the footer is enough, and the specification's own examples use both together.
Keep the single quotes when the message has a !

In bash and zsh, an exclamation mark inside double quotes starts history expansion, which reuses words from earlier commands. With "refactor(greet)!: …", zsh stops with zsh: illegal modifier: and bash with bash: : unrecognized history modifier, and nothing is committed. Single quotes pass the ! to Git as it is. Fixed: "zsh: illegal modifier" in git commit -m with an Exclamation Mark shows the error and why it happens.

Step 7: Fix a Message That Doesn't Follow the Format​

Create a .gitignore file that keeps log files out of the repository:

.gitignore
*.log

Here it's committed out of habit, with a plain message:

Terminal
git add .gitignore
git commit -m 'Add gitignore'
Output
[main 0f19381] Add gitignore
1 file changed, 1 insertion(+)
create mode 100644 .gitignore

That message has no type, so tools that read Conventional Commits skip it. As long as you haven't pushed the commit, give it a new message with --amend:

Terminal
git commit --amend -m 'chore: ignore log files'
Output
[main a926b38] chore: ignore log files
Date: Tue Nov 24 06:54:08 2026 +0000
1 file changed, 1 insertion(+)
create mode 100644 .gitignore

--amend replaces the last commit with a new one: the same changes, author and date, but the new message and a new ID (a926b38 instead of 0f19381). chore fits a change that touches neither the script nor its tests.

Amend only commits you haven't pushed. Other people may already have a pushed commit, and Git's documentation warns: "You should understand the implications of rewriting history if you amend a commit that has already been published."

Step 8: Find Commits by Type​

Now look at the whole history, one commit per line:

Terminal
git log --oneline
Output
a926b38 (HEAD -> main) chore: ignore log files
0167d9d refactor(greet)!: rename greet.sh to hello.sh
e372f43 feat(greet): wish the reader a nice day
b221545 fix: correct the spelling of Hello
faad9a8 docs: explain how to run the script
e40d909 feat: add a script that prints a greeting

Every line starts with a type, so the history reads like a list of changes. --grep keeps only the commits whose message matches a pattern. This finds the features:

Terminal
git log --oneline --grep '^feat'
Output
e372f43 feat(greet): wish the reader a nice day
e40d909 feat: add a script that prints a greeting

^feat means "a line that starts with feat", so it matches feat: and feat(greet):. This finds the breaking changes:

Terminal
git log --oneline --grep '!:' --grep 'BREAKING[ -]CHANGE'
Output
0167d9d refactor(greet)!: rename greet.sh to hello.sh

With two --grep options, Git lists the commits that match either one: a ! right before a colon, or a BREAKING CHANGE footer. [ -] matches a space or a hyphen, because the footer may also be written BREAKING-CHANGE.

A terminal in the greeter repository: git log --oneline lists six conventional commits from the first feat to the chore, the grep for feat lists the two feat commits, and the grep for breaking changes finds the refactor(greet)! commit.

This is where the format pays off. Say version 1.0.0 was released before these commits. They include features, a fix and a breaking change, and the biggest of those decides the next version: 2.0.0. Without the breaking change, the features would make it 1.1.0, and a fix alone would make it 1.0.1. Release tools such as semantic-release and release-please read commit headers this way to choose version numbers and write changelogs.

Common Mistakes​

MistakeWhat happensDo this instead
No space after the colon: feat:add a themeThe message doesn't follow the format, so tools that read it skip the commitAlways type a colon and a space: feat: add a theme
A message with ! in double quotes, in bash or zshThe shell stops with an error and nothing is committedUse single quotes
breaking change: in lowercaseThe specification says the token must be uppercase, so tools miss the breaking changeWrite BREAKING CHANGE: in capitals
A header that starts with BREAKING CHANGE:commitlint's default rules reject it (header-breaking-change)Put BREAKING CHANGE: in a footer, or add ! after the type
One commit with several unrelated changesNo single type describes itMake one commit per change, as the specification's FAQ suggests
Amending a commit you already pushedYour history no longer matches what others haveAmend only commits you haven't pushed

Troubleshooting​

SymptomLikely causeFix
zsh: illegal modifier: or zsh: no such event: 0A ! inside double quotes in zshPut the message in single quotes
bash: : unrecognized history modifier or bash: !: event not foundA ! inside double quotes in bashPut the message in single quotes
error: pathspec '…' did not match any file(s) known to gitThe message wasn't in quotes, so Git read its words as file namesPut the whole message in quotes

FAQ​

Which commit types can I use?​

Any. The specification defines only feat and fix and allows others. The list it points to is commitlint's, in the table above: build, chore, ci, docs, feat, fix, perf, refactor, revert, style and test. What matters is that everyone on the team uses the same list.

Do types have to be lowercase?​

No. The specification says tools must not treat the parts of a message as case-sensitive, except BREAKING CHANGE, which must be uppercase. Its FAQ adds: "Any casing may be used, but it's best to be consistent." The specification's own examples are all lowercase, and commitlint's default rules require lowercase types.

What if a commit fits more than one type?​

The specification's answer: "Go back and make multiple commits whenever possible." A commit that adds a feature and fixes an unrelated bug is easier to understand, and to undo, as two commits.

How do I write a revert commit?​

The specification leaves reverts to tools, and recommends the revert type with a footer that lists the IDs of the commits being reverted:

Commit message
revert: let us never again speak of the noodle incident

Refs: 676104e, a215868

I used the wrong type in an older commit. Can I change it?​

git commit --amend only changes the last commit. For an older one, the specification recommends git rebase -i before the commit is merged or released. After a release, it depends on the tools you use.

Can Git reject messages that don't follow the format?​

Yes. Git runs a commit-msg hook before saving a commit, and its documentation says the hook "can also be used to refuse the commit after inspecting the message file". commitlint is a tool built for that check.

Conclusion​

A conventional commit starts with a type, an optional scope and !, a colon and a space, and a short description. A body and footers can follow, each after a blank line. In the practice repository, each -m added one paragraph, single quotes kept the ! safe in every shell, and --amend fixed a message that didn't follow the format. In return, git log --grep can pick out features, fixes and breaking changes, and the history itself says what the next version number should be.

Additional Resources​