用途
git-commit-push 用于自动化 Git 提交与推送流程。它分析代码变更,生成符合 Conventional Commits 规范的描述性提交信息,暂存文件、提交并推送到远程仓库。
主要能力
- 检查 git 状态,识别变更类型(功能、修复、重构等)。
- 使用
git add .或指定文件暂存变更。 - 根据变更内容生成 Conventional Commits 格式的提交信息。
- 执行提交并推送到远程仓库。
- 推送后针对 Vercel 部署提供缓存清理提醒:若更改了资源或希望更新尽快在所有设备上可见,可运行
npm run cache:purge(或 Vercel → Settings → Caches)。相关参考见 skill build-start 和 docs/CACHE_PURGE_ANTES_DEPLOY.md。
使用方式
快速开始
- 检查 git 状态查看变更:
git status - 暂存所有变更:
git add . - 生成符合 Conventional Commits 的描述性提交信息
- 使用该信息提交
- 推送到远程仓库
提交信息格式
使用 Conventional Commits 格式:
<type>(<scope>): <subject>
<body>
<footer>
类型(Types)
- feat: 新功能
- fix: 缺陷修复
- docs: 文档变更
- style: 代码风格变更(格式化、缺失分号等)
- refactor: 代码重构
- perf: 性能改进
- test: 添加或更新测试
- chore: 维护任务、依赖、构建配置
- ci: CI/CD 变更
作用域(Scope,可选)
受影响的组件、模块或区域(例如 auth、products、admin)。
主题(Subject)
- 使用祈使语气:用 "add" 而非 "added" 或 "adds"
- 首字母小写
- 结尾不加句号
- 最多 72 个字符
正文(Body,可选)
- 解释 WHAT 和 WHY,而非 HOW
- 每行 72 字符换行
- 多个变更使用项目符号
- 引用问题:"Closes #123"
页脚(Footer,可选)
- 破坏性变更:
BREAKING CHANGE: <description> - 问题引用:
Closes #123、Fixes #456
工作流步骤
- 检查状态:
git status,审查变更文件,识别变更类型。 - 暂存变更:
git add .或git add path/to/file1.ts path/to/file2.tsx。 - 生成提交信息:分析变更并创建提交信息。多个相关变更归入一个提交并使用项目符号;不相关变更建议分开提交;破坏性变更在页脚包含
BREAKING CHANGE:;修复问题在页脚引用问题编号。 - 提交:`git commit -m "type(scope): subject
body
footer"。多行信息可使用:git commit -m "type(scope): subject" -m "body line 1" -m "body line 2"。 5. **推送**:git push或指定分支git push origin main`。
最佳实践
- 每个提交一个逻辑变更:不要混合不相关变更。
- 编写清晰、描述性的信息。
- 使用现在时、祈使语气:"add feature" 而非 "added feature"。
- 引用问题:在适用时将提交链接到问题/工单。
- 保持提交聚焦:如果做了很多变更,考虑多个提交。
- 提交前测试:确保代码在提交前可工作。
- 审查暂存变更:提交前使用
git diff --staged。
常见场景示例
性能优化
git commit -m "perf: optimize component rendering
- Implement React.memo for expensive components
- Add lazy loading for below-fold content
- Reduce bundle size by 40KB
Impact: ~1.3s improvement in initial load time"
数据库迁移
git commit -m "feat(database): add indexes for product queries
- Create composite index on categories(display_order, name)
- Add index on products(slug, is_active)
- Optimize JOIN queries with product_categories indexes
Migration: 20260123_optimize_data_server_queries"
文档更新
git commit -m "docs: add performance optimization guide
- Document optimization strategies
- Add examples and best practices
- Include metrics and impact analysis"
缺陷修复
git commit -m "fix(images): resolve lazy loading issue
- Fix images not loading with lazy attribute
- Add proper error handling for failed loads
- Update sizes attribute for responsive images
Fixes #789"
错误处理
如果推送失败:
- 检查远程分支是否领先:
git fetch - 拉取并合并:
git pull origin main - 如有冲突则解决
- 再次推送:
git push
如果提交失败:
- 检查 git 配置:
git config user.name和git config user.email - 确认在正确分支上:
git branch - 检查未提交变更:
git status
注意事项
- 提交前始终用
git status验证变更。 - 使用
git diff --staged审查将要提交的内容。 - 对于上次提交的小修复,可考虑使用
git commit --amend(推送前)。 - 仅在绝对必要时使用
git commit --no-verify(绕过钩子)。
适用场景
适用于需要自动化 Git 提交与推送流程的开发工作流,尤其是希望统一提交信息规范、减少手动编写提交信息负担的团队或个人开发者。也适用于使用 Vercel 部署并需要推送后清理缓存的场景。
限制
资料未提供关于该技能的具体平台限制、依赖要求或收费信息。