Get the FREE Ultimate OpenClaw Setup Guide →

git-atomic-commits

Scanned
npx machina-cli add skill saadjs/agent-skills/git-atomic-commits --openclaw
Files (1)
SKILL.md
4.2 KB

Git Atomic Commits

Goal

Transform all uncommitted changes into atomic Conventional Commits.

Stop only when git status is clean (and no untracked files remain unless explicitly told to leave them).

Definition: Atomic Commit

A commit should answer:

“What single logical change does this introduce?”

An atomic commit is easy to:

  • review
  • revert
  • bisect/debug

Avoid mixing concerns (feature + refactor + formatting) in one commit.

Workflow

  1. Check status:

    • git status -sb
    • Stop if clean.
  2. Confirm branch:

    • git branch --show-current (or git rev-parse --abbrev-ref HEAD)
    • If detached HEAD, ask the user to create a branch before committing.
  3. Branch safety gate

    • If the current branch is main or master and there are changes to commit, do not commit.
    • Ask the user to create a working branch first:
      git switch -c <branch-name>
      
    • Then re-run git status -sb and continue.
  4. Inspect scope:

    • git diff --stat
    • git diff (as needed)
  5. Identify atomic units (one purpose each):

    • dependencies
    • config/build/CI
    • refactor (behavior-preserving)
    • bug fix
    • feature slice
    • tests
    • docs
    • formatting-only
  6. Stage ONLY what belongs to one atomic unit:

    • Prefer git add -p for mixed files.
    • Use whole-file staging when the file is cohesive.
  7. Commit with Conventional Commits message.

  8. Repeat:

    • After each commit, run git status -sb
    • Continue staging/committing atomic units until clean.

Atomic Grouping Rules

  • Dependencies

    • If manifests change (e.g., package.json, pyproject.toml), commit them with lockfiles in the same commit.
    • Prefer build(deps): ... or chore(deps): ....
  • Config / CI / Build

    • Keep build, lint, and CI config changes in their own commit.
  • Refactors

    • Refactors must not change behavior.
    • Never mix refactors with feature work or bug fixes.
  • Bug fixes

    • Keep the fix isolated from refactors and formatting when possible.
  • Feature work

    • Prefer one commit per “feature slice” (a coherent, reviewable increment), not “the whole feature” if large.
  • Tests

    • Include tests with the change they validate when feasible.
    • If tests are a separate logical unit, commit them separately as test:.
  • Docs

    • Docs-only changes should be a docs: commit.
  • Formatting

    • Formatting-only changes should be separate (style:), never bundled with logic changes.

Conventional Commit Rules

  • Use type(scope): subject or type: subject
  • Keep subject short, imperative, and specific
  • Suggested types: feat, fix, chore, refactor, docs, test, build, ci, style

Examples:

  • feat(auth): add OAuth login
  • fix(api): handle timeout errors
  • refactor(cache): simplify invalidation logic
  • build(deps): bump react to 19.0.0
  • style: format codebase

Safety Checks

  • Do not include unrelated changes in the same commit.
  • If a file mixes unrelated edits and hunk-splitting is ambiguous, ask before proceeding.
  • Confirm intent before committing generated files or large diffs.
  • Avoid committing build artifacts (dist/, build/, coverage/, compiled outputs) unless the repo intentionally tracks them.
  • Ensure deletions and renames are included when relevant.

History Quality Check

Before finishing, verify:

✔ Each commit has one purpose
✔ Commit messages explain intent
✔ Commits can be reviewed independently
✔ Commits can be reverted safely

Optional: History Cleanup

If the current commit sequence contains WIP/noisy commits (or the user wants a cleaner story), offer an interactive rebase:

git rebase -i <base-branch>

Squash/reword/reorder so each remaining commit is atomic and clearly described.

Command Pattern

Inspect:

  • git status -sb
  • git diff --stat
  • git diff

Stage:

  • git add -p
  • git add <file>

Commit:

  • git commit -m "type(scope): subject"

Repeat until clean.

Source

git clone https://github.com/saadjs/agent-skills/blob/main/skills/git-atomic-commits/SKILL.mdView on GitHub

Overview

Git Atomic Commits helps you convert uncommitted changes into a sequence of atomic Conventional Commits. Each commit should answer a single logical change, making history easy to review, revert, and bisect. Use this before opening a PR or merging to produce a clean, reviewable history.

How This Skill Works

It guides you through status checks, branch validation, and isolating work into atomic units such as dependencies, config/CI, refactor, bug fixes, feature slices, tests, docs, and formatting. You stage only what belongs to one atomic unit (git add -p for mixed files) and commit with a Conventional Commit message, repeating until git status is clean.

When to Use It

  • Before you open a PR or merge to ensure a clean, reviewable history where each commit has one purpose.
  • When a large change touches multiple concerns (dependencies, code, tests, docs), to isolate each as its own commit.
  • During feature slicing, so each logical increment is reviewable and reversible.
  • After updates to dependencies or CI configurations to keep these changes in their own commits.
  • When doing refactors that preserve behavior to avoid mixing with bug fixes or features.

Quick Start

  1. Step 1: Check your status and branch; stop if on main/master or detached HEAD.
  2. Step 2: Inspect changes with diffs and stage one atomic unit (git add -p or whole-file).
  3. Step 3: Commit with a Conventional Commit message; then re-run status and repeat until clean.

Best Practices

  • Define the atomic units before staging to guide the workflow.
  • Stage only what belongs to one atomic unit; use git add -p for mixed files.
  • Commit with a Conventional Commit type and a concise, imperative subject.
  • Review after each commit with git status and diffs to ensure a single purpose.
  • Include tests or docs in separate commits when feasible to keep changes isolated.

Example Use Cases

  • build(deps): bump react to 19.0.0
  • feat(auth): add OAuth login
  • fix(api): handle timeout errors
  • refactor(cache): simplify invalidation logic
  • style: format codebase

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers