Skip to main content

Git Commit Convention

Welcome to the GreenWave git commit guide.

Why do we need this?

Git History is Documentation. A clean commit history helps reviewers understand what you did, speeds up debugging, and allows us to automatically generate ChangeLogs.

We strictly follow the Conventional Commits specification.

1. The Format

Each commit message consists of a Header, a Body (optional), and a Footer (optional).

<type>(<scope>): <subject>

[optional body]

[optional footer(s)]

Example:

feat(ai): implement new reward function based on CO2 levels

The old function only considered traffic flow. This new logic adds
a 50% weight for environmental impact using PM2.5 sensor data.

Closes #123

2. Header (Required)

The first line must not exceed 72 characters.

type

Must be one of the following:

TypeDescriptionExample
featA new feature (MINOR version)feat(iot): add traci connection
fixA bug fix (PATCH version)fix(backend): resolve timeout error
docsDocumentation only changesdocs: update setup guide
styleFormatting, missing semi-colons, etc. (no code change)style(ai): format code with black
refactorA code change that neither fixes a bug nor adds a featurerefactor(infra): optimize docker build
perfA code change that improves performanceperf(db): add index to query
testAdding missing tests or correcting existing teststest(ai): add unit test for agent
choreChanges to the build process or auxiliary toolschore(deps): upgrade numpy
ciChanges to our CI configuration files and scriptsci: fix commitlint workflow

scope

Specific to GreenWave, indicating the module affected:

  • infra: Docker, MongoDB, Orion-LD, Server.
  • backend: API, Python scripts, Data ingestion.
  • ai: RL Agents, Model training, TensorFlow/PyTorch.
  • iot: SUMO, TraCI scripts, Sensors.
  • frontend: Dashboard, UI.
  • docs: README, Wiki.
  • deps: requirements.txt, package.json, etc.

subject

A short description of the change.

  • DO: Use the imperative mood ("add", "change", "fix", "remove").
  • DON'T: Use past tense ("added", "changed", "fixed").
  • DON'T: Capitalize the first letter (unless it's a proper noun).
  • DON'T: End with a period (.).

3. Body (Optional)

  • Use when the subject is not enough to explain the why.
  • Use the imperative mood.
  • Explain why this change is necessary, not how (the code explains the how).

Used for:

  • Breaking Changes: Start with BREAKING CHANGE: <description>.
  • Referencing Issues: Closes #123, Fixes #456.

5. Automation Tools

You don't have to remember all these rules! We have set up tools to help you.

Run the following command to start an interactive commit wizard:

npm run commit

It will guide you through the process:

? Select the type of change that you're committing: (Use arrow keys)
❯ feat: A new feature
fix: A bug fix
...
? What is the scope of this change: (ai)
? Write a short, imperative tense description: (implement reward function)

Option 2: Manual Commit

If you use standard git commit, Husky will verify your message. If it doesn't match the rules, the commit will be rejected.

6. Cheat Sheet

❌ Bad✅ GoodReason
Fixed bugfix(backend): resolve null pointer exceptionMissing scope, too vague.
Added new AI modelfeat(ai): add dqn model implementationWrong tense ("Added").
update readme.docs: update install instructions in readmeTrailing period, too short.
WIP(Don't commit WIP to main)Meaningless.
Pro Tip

Think of the commit message as completing this sentence: "If applied, this commit will..."

  • ... add a new feature. (Makes sense)
  • ... added a new feature. (Grammatically incorrect in this context)

Happy Committing!