Spaces:
Running
Running
File size: 2,280 Bytes
81aa0b5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | ---
name: commit-workflow
description: Guided git commit workflow. Use before committing changes β generates a clean commit message from the diff.
language: any
tags: git, commit, version-control
---
# Commit Workflow
When the user asks to commit changes, follow this workflow.
## Step 1: Inspect the changes
Run via `bash`:
- `git status` β see what's modified/staged/untracked
- `git diff HEAD` β full diff of staged and unstaged changes
- `git branch --show-current` β current branch
- `git log --oneline -10` β recent commits (to match style)
## Step 2: Analyze
Determine:
- What's the **single logical change** being committed?
- Are there multiple unrelated changes? If so, suggest splitting into multiple commits.
- What's the conventional commit type?
- `feat:` new feature
- `fix:` bug fix
- `docs:` documentation only
- `style:` formatting, no code change
- `refactor:` code change that neither fixes a bug nor adds a feature
- `perf:` code change that improves performance
- `test:` adding tests
- `chore:` build process, tooling, deps
## Step 3: Write the message
Format:
```
<type>(<optional scope>): <imperative subject under 72 chars>
<optional body explaining why, wrapped at 72 chars>
<optional footer like "Fixes #123">
```
Rules:
- Subject in imperative mood: "Add" not "Added" or "Adds"
- Subject lowercase, no period
- Body explains **why**, not what (the diff shows what)
- Reference issues in footer
## Step 4: Stage and commit
If specific files should be staged, run `git add <files>` explicitly. Otherwise `git add -A` is fine.
Commit with a heredoc to preserve formatting:
```bash
git commit -m "$(cat <<'EOF'
feat(auth): add OAuth2 login flow
Implements the login button, callback handler, and session
persistence using JWT in httpOnly cookies.
Fixes #142
EOF
)"
```
## Step 5: Verify
- `git log -1 --stat` to confirm the commit looks right
- `git status` to confirm clean working tree (or remaining unrelated changes)
## Anti-patterns
- β `git commit -m "fix"` β too vague
- β `git commit -m "Update file.py"` β describes what, not why
- β Mixing unrelated changes in one commit
- β Committing `node_modules/`, `.env`, build artifacts
- β Using `--no-verify` to skip hooks without explanation
|