Git Commit Skill
Create a set of logically grouped, atomic commits from the current changes.
Keep each commit's scope minimal. Stage parts of a file separately when it
contains changes that belong to different commits.
Process
- Analyze Current State
- Run
git statusandgit diff HEADto see all staged and unstaged changes - Check recent commits (
git log --oneline -20) to learn the project's commit style: whether it uses conventional commits (e.g.,feat:,fix:,docs:), typical subject line length, capitalization, and formatting
- Group Changes Logically
- Identify related changes that should be committed together
- Separate unrelated changes into different commits
- When a file contains more than one logical change, stage only the hunks
for the current commit. git add -p is interactive and does not work in
this environment, so stage hunks through a patch instead:
```bash
git diff -- path/to/file > "$TMPDIR/full.patch"
# Copy full.patch to part.patch and delete the hunks for other commits
git apply --cached "$TMPDIR/part.patch"
git diff --cached -- path/to/file
```
When hunks are too tangled to split by patch, temporarily edit the file
to the intermediate state, git add it, then restore the final state
- Create Commits
- Stage the appropriate changes for each commit
- Write commit messages following the best practices below, matching the project's style
- Verify each commit with
git show - After all commits, run
git statusto confirm nothing was missed
Commit Message Format Detection
- If 80% or more of recent commits follow conventional commits, use that format
- Match the capitalization, punctuation, and structure of existing commits — consistency matters more than personal preference
For conventional commits, see references/conventional-commits.md for
types, scopes, and breaking-change syntax. The type and scope count toward
the subject length limits below.
Git Commit Message Best Practices
A diff shows what changed; only the message can say why. Follow these
seven rules from https://cbea.ms/git-commit/, adjusted for the project's
conventions:
- Separate subject from body with a blank line -
git log --oneline,
shortlog, and rebase treat the first line as the subject
- Limit the subject line to 50 characters - A rule of thumb; 72 is the
hard limit, where GitHub truncates the subject
- Capitalize the subject line - Use lowercase when the project uses
lowercase conventional commits
- Do not end the subject line with a period
- Use the imperative mood in the subject line - The subject completes
"If applied, this commit will _". The imperative applies only to the
subject; the body can use normal prose
- Wrap the body at 72 characters - Git does not wrap text, so wrap it
by hand
- Use the body to explain what and why, not how - Describe the problem,
the previous behavior, why the change fixes it, and any side effects or
consequences a reader would not expect. The code already shows how
Not every commit needs a body. When the subject says everything, such as
Fix typo in user guide introduction, omit the body. When the change needs
context, write the body.
Pass a multi-line message through a heredoc so that the blank line and the
wrapping stay exact:
git commit -F - <<'MSG'
Summarize the change in about 50 characters
Explain the problem that this commit solves and why this approach
solves it. Wrap lines at 72 characters.
Resolves: #123
MSG
Put issue and pull request references in trailers at the end of the body,
matching the trailer style that the project already uses.
Examples
Good Examples (Traditional Style):
Refactor subsystem X for readabilityRemove deprecated methods from UserServiceFix null pointer exception in login handler
Good Examples (Conventional Commits):
feat: add user authentication middlewarefix: resolve null pointer exception in login handlerrefactor: improve subsystem X readability
Bad Examples:
fixed stuffChangeswipUpdate file.jsfeat added new feature(missing colon)Added the login handler.(past tense, trailing period)
Notes
- Verify authorship and commit details before amending