---
name: writing-git-commits-dfe1cca3cfc6
description: Split staged or uncommitted changes into conventional commits. Use when asked to commit, generate commit messages, split commits, squash commits, or reorder history.
---

# Writing Git Commits

## Workflow

1. **Inspect** — `diffs --staged` (staged) and `diffs` (unstaged); fallback to `git diff --stat` when raw line stats required
2. **Group** — cluster related changes by intent
3. **Order** — commit foundational changes first (deps, config, types), then features, then tests
4. **Write** — use the message format below
5. **Stage & commit** — `git hunks list`, `git hunks add <hunk-id>` (or `git add <paths>` for whole files), then `git commit -m "..."`

## Message Format

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

[optional body]

[optional footer]
```

### Types

| Type       | When                                    |
| ---------- | --------------------------------------- |
| `feat`     | New feature or capability               |
| `fix`      | Bug fix                                 |
| `refactor` | Code change that neither fixes nor adds |
| `docs`     | Documentation only                      |
| `test`     | Adding or updating tests                |
| `chore`    | Build, CI, deps, tooling                |
| `style`    | Formatting, whitespace, semicolons      |
| `perf`     | Performance improvement                 |

### Rules

- **Subject**: imperative mood, lowercase, no period, ≤72 chars
- **Scope**: optional, the module/area affected (e.g., `auth`, `pi`, `nix`)
- **Body**: wrap at 72 chars, explain _what_ and _why_ (not _how_)
- **Footer**: `Closes #123`, `BREAKING CHANGE: ...`
- **Atomic**: each commit compiles/passes independently
- **No mixed concerns**: don't combine a bugfix with a refactor

### Examples

```
feat(pi): add diff-renderer extension

chore: update flake inputs

fix(auth): prevent token refresh race condition

Tokens were being refreshed concurrently, causing 401s for
in-flight requests. Added a mutex around the refresh call.

Closes #42

refactor(shell): extract zsh plugin config to module
```

## Grouping Heuristics

- Same file touched for different reasons → separate commits
- Multiple files for one feature → single commit
- Formatting/whitespace mixed with logic → split them
- Dependency updates → own commit (`chore(deps): ...`)
- Generated files (lockfiles, schemas) → commit with the change that caused them


---
Source attribution: edmundmiller
Original project: https://github.com/edmundmiller/dotfiles/blob/a60ca3c122ffc91fdb3d63db156b1e30851c9872/skills/catalog/writing-git-commits/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

The MIT License (MIT)

Copyright (c) 2020 Edmund Miller

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: edmundmiller
Original project: https://github.com/edmundmiller/dotfiles/blob/a60ca3c122ffc91fdb3d63db156b1e30851c9872/skills/catalog/writing-git-commits/SKILL.md
Attribution basis: Source repository record

Fields of work: Development & Engineering
Roles: Backend Developer, DevOps / SRE, Frontend Developer, Full-Stack Developer, QA / Test Engineer
Specialties: Word Documents, Frontend, Git, Testing
Tools: Tool not specified
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: c06f9cfca3bd52ff087f452f77e1fba4ed8a17dccaf0c51a5bbaaa9bbc51be8e
