|
| 1 | +--- |
| 2 | +description: "Commit and push changes with a descriptive message" |
| 3 | +argument-hint: "[optional-context]" |
| 4 | +mode: code |
| 5 | +--- |
| 6 | + |
| 7 | +1. Analyze the current changes to understand what needs to be committed: |
| 8 | + |
| 9 | + ```bash |
| 10 | + # Check for staged and unstaged changes |
| 11 | + git status --short |
| 12 | + |
| 13 | + # View the diff of all changes (staged and unstaged) |
| 14 | + git diff HEAD |
| 15 | + ``` |
| 16 | + |
| 17 | +2. Based on the diff output, formulate a commit message following conventional commit format: |
| 18 | + |
| 19 | + - **feat**: New feature or functionality |
| 20 | + - **fix**: Bug fix |
| 21 | + - **refactor**: Code restructuring without behavior change |
| 22 | + - **docs**: Documentation changes |
| 23 | + - **test**: Adding or updating tests |
| 24 | + - **chore**: Maintenance tasks, dependencies, configs |
| 25 | + - **style**: Formatting, whitespace, no logic changes |
| 26 | + |
| 27 | + Format: `type(scope): brief description` |
| 28 | + |
| 29 | + Examples: |
| 30 | + |
| 31 | + - `feat(api): add user authentication endpoint` |
| 32 | + - `fix(ui): resolve button alignment on mobile` |
| 33 | + - `refactor(core): simplify error handling logic` |
| 34 | + - `docs(readme): update installation instructions` |
| 35 | + |
| 36 | +3. Stage all unstaged changes: |
| 37 | + |
| 38 | + ```bash |
| 39 | + git add -A |
| 40 | + ``` |
| 41 | + |
| 42 | +4. Commit with the generated message: |
| 43 | + |
| 44 | + ```bash |
| 45 | + git commit -m "type(scope): brief description" |
| 46 | + ``` |
| 47 | + |
| 48 | + **If pre-commit hooks fail:** |
| 49 | + |
| 50 | + - Review the error output (linter errors, type checking errors, etc.) |
| 51 | + - Fix the identified issues in the affected files |
| 52 | + - Re-stage the fixes: `git add -A` |
| 53 | + - Retry the commit: `git commit -m "type(scope): brief description"` |
| 54 | + |
| 55 | +5. Push to the remote repository: |
| 56 | + |
| 57 | + ```bash |
| 58 | + git push |
| 59 | + ``` |
| 60 | + |
| 61 | + **If pre-push hooks fail:** |
| 62 | + |
| 63 | + - Review the error output (test failures, linter errors, etc.) |
| 64 | + - Fix the identified issues in the affected files |
| 65 | + - Stage and commit the fixes using steps 3-4 |
| 66 | + - Retry the push: `git push` |
| 67 | + |
| 68 | +**Tips for good commit messages:** |
| 69 | + |
| 70 | +- Keep the first line under 72 characters |
| 71 | +- Use imperative mood ("add", "fix", "update", not "added", "fixes", "updated") |
| 72 | +- Be specific but concise |
| 73 | +- If multiple unrelated changes exist, consider splitting into separate commits |
| 74 | + |
| 75 | +**Common hook failures and fixes:** |
| 76 | + |
| 77 | +- **Linter errors**: Run the project's linter (e.g., `npm run lint` or `pnpm lint`) to see all issues, then fix them |
| 78 | +- **Type checking errors**: Run type checker (e.g., `npx tsc --noEmit`) to identify type issues |
| 79 | +- **Test failures**: Run tests (e.g., `npm test` or `pnpm test`) to identify failing tests and fix them |
| 80 | +- **Format issues**: Run formatter (e.g., `npm run format` or `pnpm format`) to auto-fix formatting |
0 commit comments